Skip to content

Instantly share code, notes, and snippets.

@amolok
Created November 23, 2012 06:04
Show Gist options
  • Save amolok/4134203 to your computer and use it in GitHub Desktop.
Save amolok/4134203 to your computer and use it in GitHub Desktop.
cmd: Windows 7 batch loop file renumber with leading zeroes
@echo off
echo renumber.cmd folder start total
echo ===============================
setlocal EnableDelayedExpansion
set /a start = %2
if NOT DEFINED [%3] (
for %%a in (.\%1\*.png) do ( set /a i+=1 )
echo Total files in folder %1: !i!
set /a total = i
) ELSE (
set /a total = %3
)
if !start! LSS 0 ( set /a start=total+start )
set /a end = total - start
set /a i=start
REM echo i=!i!, start=!start!, total=!total!, end=!end!
echo Renumber *.png in _folder_ from _start_ (will be named as zero) and loop after _total_
echo ---------------------------------------------------------------------------------------
for %%a in (.\%1\*.png) do (
REM templete for leading zeroes goes here:
SET newname=0000!i!
SET newname=!newname:~-4!
set /a i+=1
if !i! GEQ !total! ( set /a i=0 )
REM filename template goes here:
ren %%a !newname!.new
)
echo ---------------------------------------------------------------------------------------
REM final renaming
ren .\%1\*.new *.png
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment