I’ve blogged about this some time ago under another topic (Creating-daily-log-files) but I find myself regularly searching for it again when I have to create a new batch file for something plus have to output some uniquely named log file.
Situation:
You have some script/batch file that does some stuff/maintenance/imports whatever. It runs from some kind of scheduler unattended so you need to have it generate a log file in case there were errors/issues. Creating an output log file is fairly easy but having it create a new name each day/time is a bit more tricky.
Possible solution:
This script assumes a date time format of yyyy/mm/dd
SET UNIQUESTR=%date:~0,4%%date:~5,2%%date:~8,2%%time:~0,2%%time:~3,2%
MyTool.exe > MyTool%UNIQUESTR%.log
This will create a log file with a date and time stamp each time it is run (assuming you don’t run it twice in the same second)
Have fun kids!
Update: a nice site with some helpful info -> http://www.dostips.com/DosCommandIndex.php