Sunday, 30 June 2019

Batch file rename with suffix as 01 02 03 04 and so on

I have bunch of files with similar keyword like


computer-stock-photo.jpg 
computer-stock-picture.jpg
computer-picture.jpg

What I want to do is suffix serial wise 2 digit numbers like


computer-stock-photo-01.jpg, 
computer-stock-picture-02.jpg,
computer-picture-03.jpg

Also, the batch script should work with any extension like jpg or png.


The script I tried:


@echo off
setlocal disableDelayedExpansion
set "chars=0123456789"
for /f "eol=: delims=" %%F in ('dir /b /a-d *.jpg') do call :renameFile "%%F"
exit /b

:renameFile
setlocal enableDelayedExpansion
:retry
set "name="
for /l %%N in (1 1 8) do (
set /a I=!random!%%36
for %%I in (!I!) do set "name=!name!!chars:~%%I,1!"
)
echo if exist !name!.jpg goto :retry
endlocal & ren %1 %name%.jpg

The above script only work for jpg and add random numbers not serial wise.

No comments:

Post a Comment

How can I VLOOKUP in multiple Excel documents?

I am trying to VLOOKUP reference data with around 400 seperate Excel files. Is it possible to do this in a quick way rather than doing it m...