Command line and strings

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

Leave a Comment


NOTE - You can use these HTML tags and attributes:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>