Summary
- gets current date/time and creates a string in the form of MMDD.HHMM
- used for renaming files/logs
::Drop a file on this cmd to append time stamp to the filename @echo off ::=============Capure Time and assign to vars ======================================== time /t date /t ::Get The Date and Formate to 4 chars :: Use this for testing different times ::FOR /f "delims=:, tokens=1,2" %%I IN ("12:11 AM") do set theHour=%%I & set theMinute=%%J FOR /f "delims=:, tokens=1,2" %%I IN ('time /t') do set theHour=%%I & set theMinute=%%J FOR /f "tokens=2" %%I IN ('date /t') do set theDate=%%I set theDate=%theDate:~0,2%%theDate:~3,2% ::get the A/P to determine how to convert the hours to 24HR set theAmPm=%theMinute:~3,1% ::parser sticks on a trailing blank, strip it off set theHour=%theHour:~0,2% ::strip the am/pm character set theMinute=%theMinute:~0,2% echo CAPTURED TIME : [%theDate%.%theHour%.%theMinute%.%TheAmPm%] ::if AM and hour is 12.. set to 00 if "%TheAmPm%" == "A" ( if "%theHour%" == "12" ( set theHour=00 ) ) ::if PM drop any leading 0 if "%TheAmPm%" == "P" ( if "%theHour:~0,1%" == "0" ( set /a theHour=%theHour:~1,1% ) ) ::If PM, then add 12 if "%TheAmPm%" == "P" ( if %theHour% LSS 12 ( set /a theHour=%theHour%+12 ) ) echo TRANSFORMED TIME: [%theDate%.%theHour%%theMinute%] :: ============================================== set thisExt=%~x1 set thisName=%~n1 set thisPath=%~p1 set thisPath=%~dp1 echo %1 %thisPath%%thisName%.%theDate%.%theHour%%theMinute%%thisExt% copy %1 %thisPath%%thisName%.%theDate%.%theHour%%theMinute%%thisExt% set PROGZIP=T:\tools\7-Zip\7z %PROGZIP% a -r "%thisPath%%thisName%.%theDate%.%theHour%%theMinute%%thisExt%.zip" "%thisPath%%thisName%.%theDate%.%theHour%%theMinute%%thisExt%"
- Log in to post comments
Tags