Batch file renaming with increments
Posted on 2005-05-07
How can I rename a group of files in a folder with an incremented number? The folder can be any folder located under My Pictures, & can be inputted into the batch file. I can rename files adding the date to the end (see below - not unique), but I'd rather have a unique # that is 3 digits including leading zeroes, such as beachpics001-999.jpg
IF (%1) == () GOTO syntax
REM zdate would be MMDDYY
FOR %%F IN (%zpath%\%1\*.jpg) DO ren %%F %%~nF%zdate%%%~xF
REM result would be filnamdate.ext
echo Usage: TEST.bat "FolderName"
echo Any FolderName located under "c:\my documents\my pictures\"
echo This routine will rename all files in user inputted folder with the original
echo file name plus an incremented number from 001-999 plus the file extension
So the entire middle section would be replaced with something similar to this:
FOR %%F IN (%zpath%\%1\*.txt) DO ren %%F %%~nF%INCNUM%%%~xF
What I need is the how-to of getting the variable INCNUM including the leading 0's.
I have tested the above as is & it works, but I couldn't get it to work when trying to set zpath to "c:\my documents\my pictures" - nor if I tried including my homepath location like:
(%homepath%\%zpath%\%1\*.jpg). Is there a special variable that represents the current user's my documents path?
Any help from those DOS guru's lurking around would be of great help, thx.
TheDeepFatFryer says, "Can you read me now?" :)