The following code will allow you to rename a file to the date and time. Save this code in a batch file (in this example we’ll call it rename_it.cmd), then call it with the file that needs to be renamed. You can also download it here, rename_it.cmd.
Example: rename_it FILENAME.txt
@Echo OFF
TITLE DateName
REM DateName.CMD
REM takes a filename as %1 and renames as %1_YYMMDDHHMM
REM
REM ————————————————————-
IF %1.==. GoTo USAGE
Set CURRDATE=%TEMP%\CURRDATE.TMP
Set CURRTIME=%TEMP%\CURRTIME.TMP
DATE /T > %CURRDATE%
TIME /T > %CURRTIME%
Set PARSEARG=”eol=; tokens=1,2,3,4* delims=/, ”
For /F %PARSEARG% %%i in (%CURRDATE%) Do SET YYYYMMDD=%%l%%j%%k
Set PARSEARG=”eol=; tokens=1,2,3* delims=:, ”
For /F %PARSEARG% %%i in (%CURRTIME%) Do Set HHMM=%%i%%j%%k
Echo RENAME %1 %1_%MMDDYYYY%%HHMM%
RENAME %1 %YYYYMMDD%-%HHMM%_%1
GoTo END
:USAGE
GoTo END
:END
REM
TITLE Command Prompt
Leave a Reply