Batch file renaming

April 7, 2009 at 11:22:39
Specs: Windows XP
Hello,

I could use a batch file to rename multiple files of type:

2.abc.bmp
3.xyz.bmp

to

abc.bmp
xyz.bmp

Thanks in advance


See More: Batch file renaming

Report •


#1
April 7, 2009 at 16:00:58
Below is just one method of renaming, change the paths to suit your needs:

:: Code begins...
@echo off
cls

for /f "tokens=1-3 delims=." %%1 in ('dir /a-d /b %temp%\*.bmp') do (
     set reject=%%1
     set name=%%2
     set ext=%%3 & call :renameit
)
dir %temp%\*.bmp
exit /b

:renameit
ren %temp%\%reject%.%name%.%ext% %name%.%ext%
goto :eof
:: Code ends....

Hope this helps, also hope it's not homework!.


Report •

#2
April 8, 2009 at 06:47:45
Thank you Valerie,

Nice use of tokens & delimeters! I'm embarassed to say its not homework. :)


Report •

Related Solutions


Ask Question