Welcome to MSDN Blogs Sign in | Join | Help

System.Blog.Martens.Ben

The Tech Blog of Ben Martens
Logs Named By Current DateTime

I have a scheduled task and I’d like to save logs from the output. After some quick batch file work, I came up with this.

@echo off
setlocal

for /f "tokens=2" %%A in ('date /t') DO @(set MyDate=%%A)
set MyDate=%MyDate:/=-%

set MyTime=%TIME::=-%
set MyTime=%MyTime:.=-%
set MyFilename=%MyDate%_%MyTime%.log

echo Writing output to %MyFilename%
mytask.exe > %MyFilename%

endlocal

I end up with filenames like 10-02-2009_14-34-56-00.log which gets the point across. Do you have a better way to accomplish this?

Posted: Friday, October 02, 2009 2:36 PM by benmartens

Comments

No Comments

Leave a Comment

(required) 

(required) 

(optional)

(required) 

  
Enter Code Here: Required

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Page view tracker