@echo off
setlocal EnableDelayedExpansion
set i=0
for %%X in (*.jpg;*.png) do (
set ext=%%~xX
set /a i+=1
set num=0000!i!
set name=!num:~-3!
copy "%%X" "!name!!ext!"
)
Here’s a batch file I put together for renaming some images I have padded to 3 digits (001, 002, …). While it is trivial to just go in and change the padding if I have more than 999 files in a folder, it would probably be more effective to just have the script calculate the padding required.
I am trying to do the following
1 – Get the number of files in the current directory
2 – Set that as the padding and proceed as usual
How can I do this?
You need two loops, in the first loop you only get the count of your files and the string length of the counter.
Then you set this to a variable ex.
Then you only need to change your second loop to