Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Hi,
I have a specific problem that I can't believe has not got a solution already. I have to rename some files that are in the format = (im1, im2, im3 ... im15, im16, ... im345, im 346)
Windows orders these files alphabetically, not numerically. therfore I get im1, im10, im100, im101, im102 ...
I need to convert the files into the following format = im_00001, im_00002 ... im00011, im00012 ... im00123, im00124...
This has to be AS PER the numeric order of the files, not the alphabetical order. This is what is getting me in difficulty. Has anybody got a script? or know of a batch file name convertor that can do this? I will need to do this quite a lot!!!
TIA
Philip

The following batch fits your need, it renames the files im... to im_nnnnn saving their numerical sequence.
It works under Windows NT/2K/XP environments and, of course, is tailored to your specific renaming question.To run save it as NumRen.bat (or whatecer name you like) than type NumRen Folder where Folder is the directory storing your mi files to be renamed. If that is your current directory just type NumRen . (dot).
Folder must not contain blanks.The script must be activated removing "Echo" in front of the Ren command; do it only when you are sure the result is what you planned.
@Echo Off
:: NumRen.bat Syntax: NumRen Folder
Echo.
If %1.==. (Echo Folder missing & GoTo :EOF)
If not exist %~f1 (Echo Folder "%~f1" not found & GoTo :EOF)
Echo Renaming im... in folder "%~f1"For /F "tokens=2 delims=m" %%A in ('Dir /B %~f1.\im*.*') Do Call :REN %1 %%A
Set FNo=
GoTo :EOF:REN
Set FNo=%2
If "%FNo:~1,1%"=="" Set FNo=0000%FNo%
If "%FNo:~2,2%"=="" Set FNo=000%FNo%
If "%FNo:~3,3%"=="" Set FNo=00%FNo%
If "%FNo:~4,4%"=="" Set FNo=0%FNo%
Echo Ren "%~f1.\im%2" "im_%FNo%"
GoTo :EOFThat worked fine under Win 2K, if you need more support or anything goes wrong post again.

Philip,
sorry, but I prefer you store the script below, as the previous holds some bugs.
Too fast means sometime bugs too.@Echo Off
:: NumRen.bat Syntax: NumRen Folder
Echo.
If %1.==. (Echo Folder missing & GoTo :EOF)
If not exist %~f1.\Nul (Echo Folder "%~f1" not found & GoTo :EOF)
Echo Renaming im... in folder "%~f1"For /F "tokens=2 delims=m" %%A in ('Dir /B %~f1.\im*.*') Do Call :REN %1 %%A
GoTo :EOF:REN
Set FNo=%2
If "%FNo:~1,1%"=="" Set FNo=0000%FNo%
If "%FNo:~2,1%"=="" Set FNo=000%FNo%
If "%FNo:~3,1%"=="" Set FNo=00%FNo%
If "%FNo:~4,1%"=="" Set FNo=0%FNo%
Echo Ren "%~f1.\im%2" "im_%FNo%"
GoTo :EOF

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |