I would appreciate method which can rename files with random names into the following: 00, 01, 02, ...
Is there any automated method?
I would appreciate method which can rename files with random names into the following: 00, 01, 02, ...
Is there any automated method?
Borrowing from these answers here and here and on my own to figure out how to prefix a "0" in front of files 0-9, the following is what I came up with, a simple renumber.bat file can be created.
setlocal enabledelayedexpansion
set /a count=0
for /r %%i in (*.jpg) do (
echo %%i
if !count! LSS 10 rename %%i 0!count!.jpg
if !count! GEQ 10 rename %%i !count!.jpg
set /a count+=1
)
Save the above code snippet to a file called "renumber.bat" in the directory of jpg files you want to rename. Then simply invoke "renumber.bat" from the command line. Of course, your should backup all these files anyway. It's always possible my script has a bug...
This should do:
@SETLOCAL ENABLEDELAYEDEXPANSION
@set /a counter=1
@set counterFormatted="1"
@for /f "tokens=*" %%f in ('dir /b *.jpg') do @(
@set counterFormatted=00000!counter!
@rename %%f !counterFormatted:~-5!.jpg
@set /a counter = !counter! + 1
)
It will automatically pad the number too. You can modify the padding easily by changing the amount of zeroes added to counterFormatted
and modifying the ~-5
in the rename based on your requirements.
Just put it in a bat
file somewhere and run it in the directory with your files. If you want to rename files with different extensions, you can modify the filter in the dir
just as you're used to, and then the rename
line like so:
@rename %%f !counterFormatted:~-5!%%~xf
Be careful not to put the bat
file in the same folder in that case, otherwise it will be renamed as well :)