|
Answer» I want to rename a file from file.log to file_YYMMDD.log
i currently have this bat script but it only renames file.log to file_MMDDYYY.log. any idea how to GET YYMMDD?
here's the code that I have.
REM --- Go to the directory of the file to rename cd D:
@Echo OFF TITLE DateName REM DateName.CMD REM takes a filename as FileName.log and renames as FileName_MMDDYYYYHHMM.log REM REM ------------------------------------------------------------- IF FileName.log.==. GoTo USAGE Set CURRDATE=%TEMP%\CURRDATE.TMP
DATE /T > %CURRDATE%
Set PARSEARG="eol=; tokens=1,2,3,4* delims=/, " For /F %PARSEARG% %%i in (%CURRDATE%) Do SET MMDDYYYY=%%J%%k%%l
Echo RENAME FileName.log FileName_%MMDDYYYY%.log RENAME FileName.log FileName_%MMDDYYYY%.log GoTo END
:USAGE Echo Usage: DateName filename Echo Renames filename to filename_MMDDYYYY GoTo END
:END change the order of variables:
For /F %PARSEARG% %%i in (%CURRDATE%) Do SET MMDDYYYY=%%l%%j%%kyup. im geting 20060206 (YYYYMMDD) i need 060206 (YYMMDD) instead. is there a way to PARSE 2006 to just 06?Yes, add one new line:
For /F %PARSEARG% %%i in (%CURRDATE%) Do SET MMDDYYYY=%%l%%j%%k SET MMDDYYYY=%MMDDYYYY:~-6%thanks carlos. it WORKED!
|