Link to home
Start Free TrialLog in
Avatar of Sabir
Sabir

asked on

Renaming multiple files in DOS

I am trying to write a batch file that automatically renames all the files in the current directory into a 3 digit number.

ie 000, 001, 002

I have quite a lot of files which need changing into the format and rather than changing each one individually, it easierto create a batch file.

I would be gratefull if anyone can offer me some help with this.

Thanks in advance
Avatar of For-Soft
For-Soft
Flag of Poland image

It would be much easier, if we could know you operating system version.
hello,

assuming XP, 2000 or 2003 (don't know about NT:

                           _____________
_______________| NUMBER.CMD |_____________________

@echo off
setlocal
set count=0

for /f "usebackq delims=" %%x in (`dir /a:-d /b "C:\TEMP\*.*"`) DO CALL :NUMBER %%x
goto :EOF

:NUMBER
set NAME=%~n1%
set EXT=00%count%
set EXT=%EXT:~-3%
echo ren "%1" "%NAME%.%EXT%"
set /a count+=1
goto :EOF

_______________ END OF NUMBER.CMD _____________________

You have to replace C:\TEMP with the folder your files are in ( You can't put this bachfile in your folder; it will be renamed also)
About the line: echo ren "%1" "%NAME%.%EXT%" :
it will show on yoyr screen what it will do, but doesn't actualy do it. If it shows what you want the batch to do, remove the echo statement

Good luck.

NB: For-Soft is absolutely right: we need more information here!
ECHO OFF
set n1=0
set n2=0
set n3=0

for %%a in (c:\temp\1\*.*) do call renameit.bat %%a

set n1=
set n2=
set n3=
set nx=
ASKER CERTIFIED SOLUTION
Avatar of For-Soft
For-Soft
Flag of Poland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Sabir
Sabir

ASKER

Thanks for the help.

Sorry for being so vague with the details.

I am using DOS in Win XP to  run the program.

The files that I wanted to rename were jpeg files.

I have had to amend the code slightly to ensure the files stay as jpegs by adding ".jpeg" to the first line in renameit.bat.

ie. rename %1 %n3%%n2%%n1%.jpeg

Thanks again for your help.