Batch file renaming question

April 21, 2011 at 13:12:42
Specs: Windows XP, AMD 9550
I have folders with large numbers of randomly named .jpg files that I want to rename in sequence like this:

apple.jpg ==> File 001.jpg
Bertha.jpg ==> File 002.jpg
coins.jpg ==> File 003.jpg
cow.jpg ==> File 004.jpg
yams.jpg ==> File 277.jpg
zebra.jpg ==> File 278.jpg

Is there a simple way to have a DOS batch file enumerate and rename files in this way?

See More: Batch file renaming question

Report •

April 22, 2011 at 02:07:12
It seems that the file names are sorted alphabetically and the list is renamed in sequence.

Report •

April 22, 2011 at 08:21:28
Yes, that's what I want the batch file to do: sort the file names in a given folder alphabetically and rename them with a common base name, incremented.

Report •

April 22, 2011 at 16:19:51
Limiting to only three digits seems a little inadequate, but anyway...

@echo off
SetLocal EnableDelayedExpansion

pushd "t:\he\dir"

set filecnt=0

for /f "delims=" %%a in (' dir /b /on /a-d *.jpg ') do (
    set /a filecnt+=1
    set filenum=00!filecnt!
    set filenum=!filenum:~-3!
    echo ren "%%~a" "file !filenum!.jpg"


Remove the "echo" after testing.

Report •

Related Solutions

Ask Question