Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Hi,
I need to append a date stamp to an output file name. Eg, abc_.txtI tried using abc_%date%.txt as the output file syntax and it wouldn't accept. I could echo %date% correctly though.
Any tips?
Thanks in advance!
Edwin Lee

I've managed to come up with a solution to my problem, and I'm sharing it with the rest:
Basically, I used 2 batch files; the first one, date1.bat sets the date/time. The second batch file, dumplog.cmd is an example of an event log dump with date/time stamp on it.
REM Assumes MM-DD-YYYY format.
REM Assumes date separator is "/".
IF NOT '%1'=='' GOTO SetEnvVars
for /F "delims=/ tokens=1-4" %%i in ('date /t') do MMDDNT.BAT %%i %%j %%k
%%l
GOTO Done:SetEnvVars
set DayOfWeek=%1
set Month=%2
set Day=%3
set Year=%4
set Date=%1 %2/%3/%4:Done
@echo off
REM ******************** Event Log dump for SERVERNAME ************************
REM **************************************************************************
REM Define the locations of the relevant files
D:
CD\eventlogREM **************************************************************************
REM Set variables for time and date
call D:\eventlog\mmddnt.batset logdir=d:\eventlog\logs
set syslogfile=syslog
set seclogfile=seclog
set applogfile=applog
REM **************************************************************************
REM Create the logdirectory if required
if not exist %logdir% md %logdir%REM **************************************************************************
REM Reset the dump file for today
echo Date,Time,Type,Category,EventID,Source,User,Computer,Detail >%month%%day%%year%%syslogfile%.csvREM **************************************************************************
REM - Update Log
echo Beginning event log dump Update >>%month%%day%%year%%syslogfile%.csv
echo %month% %day%, %year% >>%month%%day%%year%%syslogfile%.csv
time /t >>%month%%day%%year%%syslogfile%.csv
echo\ >>%month%%day%%year%%syslogfile%.csv
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ >>%month%%day%%year%%syslogfile%.csv
echo\ >>%month%%day%%year%%syslogfile%.csv
dumpel -t -c -d 1 -l system >> %month%%day%%year%%syslogfile%.csvREM **************************************************************************
REM - Update Log
echo Event logs dumped to file - Complete >>%month%%day%%year%%syslogfile%.csv
echo %month% %day%, %year% >>%month%%day%%year%%syslogfile%.csv
time /t >>%month%%day%%year%%syslogfile%.csv
echo\ >>%month%%day%%year%%syslogfile%.csv
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ >>%month%%day%%year%%syslogfile%.csv
echo\ >>%month%%day%%year%%syslogfile%.csvREM **************************************************************************
REM Reset the dump file for today
echo Date,Time,Type,Category,EventID,Source,User,Computer,Detail >%month%%day%%year%%seclogfile%.csvREM **************************************************************************
REM - Update Log
echo Beginning event log dump Update >>%month%%day%%year%%seclogfile%.csv
echo %month% %day%, %year% >>%month%%day%%year%%seclogfile%.csv
time /t >>%month%%day%%year%%seclogfile%.csv
echo\ >>%month%%day%%year%%seclogfile%.csv
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ >>%month%%day%%year%%seclogfile%.csv
echo\ >>%month%%day%%year%%seclogfile%.csvdumpel -t -c -d 1 -l security >> %month%%day%%year%%seclogfile%.csv
REM **************************************************************************
REM - Update Log
echo Event logs dumped to file - Complete >>%month%%day%%year%%seclogfile%.csv
echo %month% %day%, %year% >>%month%%day%%year%%seclogfile%.csv
time /t >>%month%%day%%year%%seclogfile%.csv
echo\ >>%month%%day%%year%%seclogfile%.csv
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ >>%month%%day%%year%%seclogfile%.csv
echo\ >>%month%%day%%year%%seclogfile%.csvREM **************************************************************************
REM Reset the dump file for today
echo Date,Time,Type,Category,EventID,Source,User,Computer,Detail >%month%%day%%year%%applogfile%.csvREM **************************************************************************
REM - Update Log
echo Beginning event log dump Update >>%month%%day%%year%%applogfile%.csv
echo %month% %day%, %year% >>%month%%day%%year%%applogfile%.csv
time /t >>%month%%day%%year%%applogfile%.csv
echo\ >>%month%%day%%year%%applogfile%.csv
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ >>%month%%day%%year%%applogfile%.csv
echo\ >>%month%%day%%year%%applogfile%.csvdumpel -t -c -d 1 -l application >> %month%%day%%year%%applogfile%.csv
REM **************************************************************************
REM - Update Log
echo Event logs dumped to file - Complete >>%month%%day%%year%%applogfile%.csv
echo %month% %day%, %year% >>%month%%day%%year%%applogfile%.csv
time /t >>%month%%day%%year%%applogfile%.csv
echo\ >>%month%%day%%year%%applogfile%.csv
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ >>%month%%day%%year%%applogfile%.csv
echo\ >>%month%%day%%year%%applogfile%.csv

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |