Computing.Net > Forums > Programming > Appending date to file name

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Appending date to file name

Reply to Message Icon

Name: Edwin Lee
Date: January 25, 2002 at 11:07:32 Pacific
Comment:

Hi,
I need to append a date stamp to an output file name. Eg, abc_.txt

I 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



Sponsored Link
Ads by Google

Response Number 1
Name: radon
Date: January 26, 2002 at 15:10:13 Pacific
Reply:

What language?


0

Response Number 2
Name: Edwin Lee
Date: July 12, 2002 at 06:51:26 Pacific
Reply:

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\eventlog

REM **************************************************************************
REM Set variables for time and date
call D:\eventlog\mmddnt.bat

set 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%.csv

REM **************************************************************************
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%.csv

REM **************************************************************************
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%.csv

REM **************************************************************************
REM Reset the dump file for today
echo Date,Time,Type,Category,EventID,Source,User,Computer,Detail >%month%%day%%year%%seclogfile%.csv

REM **************************************************************************
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%.csv

dumpel -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%.csv

REM **************************************************************************
REM Reset the dump file for today
echo Date,Time,Type,Category,EventID,Source,User,Computer,Detail >%month%%day%%year%%applogfile%.csv

REM **************************************************************************
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%.csv

dumpel -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



0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

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


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Appending date to file name

Append date within file to name of file www.computing.net/answers/programming/append-date-within-file-to-name-of-file/19514.html

Batch file append date to file nm? www.computing.net/answers/programming/batch-file-append-date-to-file-nm/18658.html

DOS: Adding date to file name. www.computing.net/answers/programming/dos-adding-date-to-file-name/11491.html