The batch file as been modified for 3 digits.
I missed of a couple of lines that contained the Count.
The Batch file can be stored in the working directory or stored in
your path.
Type "Path" to list the directories the O/S looks in to
find a file. you can add your own directory to this path
everytime the O/s starts, but the easiest way is to add
something like this to the batch file.
set path=MyDir;%path%.
Hope you unstandstand the program better any questions
just ask.
@echo off
rem Set Count var to 1
set Count=001
rem Find all files with 0-9 first digit and
rem 0-9 second digit and save into tmp1.txt.
rem If you add a extra digit to the existing
rem filenames then add a extra [0-9] to
rem the findstr command below.
dir /b | findstr /i "File[0-9][0-9]" > tmp1.txt
rem Sort Tmp1.txt file at the 5 character
rem saving it to Tmp2.txt.
sort tmp1.txt /+5 > tmp2.txt
rem Go through tmp2.txt and call the label
rem ReNumber followed by each filename.
for /f %%a in (tmp2.txt) do call :ReNumber %%a
rem This would tidy up by deleting the tmp files.
rem I rem'ed it out so you could look at the files.
rem erase tmp?.txt *.tmp
rem Exit program
exit /b
rem Renumber routine %1 equals filename
rem called from the for statement.
:ReNumber %1
rem if file %1 exists rename it to
rem Old%Count% ie Old01..OLd2..ect.
if exist %1 (
rem display whats being renamed.
echo renamed %1 Old%Count%
rem Change filename to filename.tmp
rem to stop errors of File already exists.
ren %1 %1.tmp
rem rename the tmpfile without errors
ren %1.tmp Old%Count%
) else (
rem here it filname doe's not exist
rem rename no need for tmp file.
echo ren %1 Old%Count%
ren %1 old%Count%
)
rem increase count
set /a Count=%Count+1
rem add leadind zero's
if %count% LSS 100 set Count=0%count%
if %count% LSS 10 set Count=0%count%
rem end of subroutine so
rem return to for command for next filename.