Answer the question
In order to leave comments, you need to log in
How to rename files in bat file?
I have a .bat file with a folder next to it.
The folder contains .jpg files with different names. (1234567890.jpg, helloWorld.jpg, img-23012010.jpg)
I'm trying to write in a .bat file so that he renames all these files in this folder.
With this name file-001.jpg file-002.jpg file-003.jpg ... file-069.jpg
I can't implement file recalculation..
Here are examples that do not work correctly
set dir=Result\
forfiles /p %dir% /m *.jpg /c "cmd /c ren @file out-0001.jpg"
pause
SETLOCAL EnableDelayedExpansion
for /f %%I in ('dir /b ^| findstr /r ".*[.]jpg$"') do set "x=%%I" & ren "%%I" "name-001!x:~0!"
pause
set dir="Result\*.jpg"
set new="new_??.jpg"
ren %dir% %new%
pause
Answer the question
In order to leave comments, you need to log in
Here is the solution
This .bat file will rename the Jpg files from the folder like this file file-000.jpg, file-001.jpg, file-002.jpg
setlocal enabledelayedexpansion
cd /d Result
set "count=1000"
set a="*.jpg"
for /f "usebackq delims=*" %%f in (`dir /b /o:-d /tc %a%`) do (ren "%%f" file-!count:~1!.jpg
set /a count+=1
)
pause
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question