View Single Post
  #1 (permalink)  
Old November 21st, 2007, 01:21 AM
mikaelpelle mikaelpelle is offline
Registered User
 
Join Date: Nov 2007
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default Batch rename in MSDOS

My camera is creating files like 01042007011.jpg (DAYMONTHYEARNUMBER.EXT).
I would like to create a batch file that rename them to YEARMONTHDAY_NUMBER.EXT, 20070401_011.jpg in my exemple.

As I don't have delimiters, except for the extension, i don't really know how to split the different elements of the filename. I've tried something like this:

Code:
@echo off

for /F "tokens=*" %%A in ('dir *.jpg *.mp4 /B') do (
 for /F "delims=. tokens=1" %%G in ("%%A") do (
     call :_rename %%G
 )
)

goto :_end

:_rename

set filenumber=%1
set filenumber=%filenumber:~-3%
echo %filenumber%

set year=%1
set year=%year:~+4%
echo %year%

:_end
endlocal

pause
This will return:
011 -> working
2007011 -> how to remove the 011 at the end ?

The tilde with the dash (~-) permits me to return only the last 3 characters of my strings. So its working fine to get the filenumber.
I tried to do it with ~+, but it then remove an amount of characters at the beginning. So it only returns the end of the string in both case. I haven't found a way to have only the day, month and year.

Thanks for your help.
Reply With Quote