cmd - Batch file for incremental renaming of files/folders with date -
i have folder called output
. want rename using batch file output_old05aug15
, 05aug15
today's date. however, if output_old05aug15
present, output
renamed output_old05aug15_2nd
, on. need batch file renames folder accordingly.
edit: got incrementally rename folders exist. here's have done:
@echo off setlocal /d %%f in (.\output) ( if exist "output_old*" ( set reqren=y /l %%x in (2,1,999) if defined reqren if not exist "output_old_%%x" (rename "%%f" "output_old_%%x"&set "reqren=") ) else (rename "%%f" "output_old") ) goto :eof
i referred post batch file - rename , incremental folder number?
@echo off setlocal enabledelayedexpansion rem locale, ie: 'thu 08/06/2015' /f "tokens=2 delims=/ " %%m in ("%date%") set /a "n=(3*((1%%m)%%100-1))" set month=janfebmaraprmayjunjulaugsepoctnovdec set monthname=!month:~%n%,3! set dt=%date:~7,2%%monthname%%date:~-2% if exist output ( /l %%x in (1,1,999) ( if %%x equ 1 set new=output_old%dt% if %%x geq 2 set new=output_old%dt%v%%x if not exist !new! ( echo !new! rename output !new! goto fin ) ) ) :fin
i'll leave making proper ordinal indicators you. note %date% format depends on locale in case of use tokens=1 delims=/
in first for
Comments
Post a Comment