Computing.Net > Forums > Programming > Batch file renaming

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Batch file renaming

Reply to Message Icon

Name: philip cosson
Date: October 13, 2003 at 04:14:13 Pacific
OS: winNT
CPU/Ram: 1.6/512
Comment:

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



Sponsored Link
Ads by Google

Response Number 1
Name: IVO
Date: October 13, 2003 at 06:22:49 Pacific
Reply:

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 :EOF

That worked fine under Win 2K, if you need more support or anything goes wrong post again.


0

Response Number 2
Name: IVO
Date: October 13, 2003 at 06:37:00 Pacific
Reply:

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


0

Response Number 3
Name: SN
Date: October 13, 2003 at 08:43:33 Pacific
Reply:

Also note that A.F.5 rename your files, available on download.com, will work quite nicely.
-SN


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

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


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Batch file renaming

Batch file renaming www.computing.net/answers/programming/batch-file-renaming/18676.html

Automated batch-file renaming www.computing.net/answers/programming/automated-batchfile-renaming/13367.html

Batch file rename and move www.computing.net/answers/programming/batch-file-rename-and-move/14397.html