Saturday, March 30, 2013

DOS batch: renaming multiple files with a counter

In rena.bat:
echo off
cls
set i=0
setlocal ENABLEDELAYEDEXPANSION
for /r %%x in (%1) do (
 ren "%%x" "foo-"!i!".jpg" 
 set /a i=i+1
)
The above code renames all .jpg files to be prefixed with foo and with an incrementing counter. To use the code,
rena *.jpg

No comments:

Post a Comment