Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
I am trying to find a switch or command that will include the date and time in a log file generated by a batch backup job I have written. In it's current form it generates a list of the files and directories that have been backed up and appends it to the end of the log file, but I need to know when each backup was run.
This is what I have written so far....
----------------
@echo off
echo ********* Backup started ******* >> f:\test\backuplog.txt
echo * >>f:\test\backuplog.txtxcopy32 c:\temp\favs f:\test /d /s /c /r /y >> f:\test\backuplog.txt
echo * >>f:\test\backuplog.txt
echo ******** Backup Completed ***** >> f:\test\backuplog.txt
echo off
---------------
I would like the date and time to insert immediately after the "Backup started" line.Please help me if you can. Many thanks

Well, if you want to add the date and time to a file that already exists, you will need to append the date and time to that file. So the file is f:\test\backuplog.txt. What you'd do is this:
DATE /T >>f:\test\backuplog.txt
TIME /T >>f:\test\backuplog.txtIn case you're wondering, the "/T" command makes it so that it just displays the date or time rather than asking for a new date or time. I hope that works out for you!

Thanks. I have just inserted this into the BAT file and run it, and it inserts the request for a new date and time into the log file. Plus you need to press enter twice on the blank command prompt to make it complete. Any further setting required?

Watch for wrapped lines!
Place this in your batch file.
@ECHO off
%COMSPEC%/CFOR %%v in (1 2) do prompt Backup started$q$d $t$_>>%temp%.\backup.tmp
FIND "=" >f:\test\backuplog.txt
DEL %temp%.\backup.tmp
type f:\test\backuplog.txt

Man I hate this mesage board,
it really sucks - I mean the
messaging mechanics stink.BTW, the TYPE line was just for
demonstration.

Seymour, you say that it inserts the request for a new date and time into the log file. What version of DOS are you using? The "/T" command should eliminate that.

Thanks Adam and Laurence - much appreciated.
Laurence - sorry mate, your stuff was so far over my head I just had to laugh! Where does it wrap, and where are the carriage returns? I pasted your work in and tried it but the job never completes. Any ideas?
Adam - It's the DOS shell within Windows 98. When the job is run it outputs the date/time requests into the log file. Pressing enter twice on the blank command prompt screen allows the job to complete but doesn't actually insert the date/time.
Thankyou both for your help

i wish to offer an alternative to long commands;
if you goto 'my programs' you will find 'time-date logger' this will append to c:\logfile.txt, the current time/date.it is just a 5-minute job.
enjoy

Fool, nice app, but I need to be able to specify the log file's name and location. Is there an expanded configuration option?

Windows 2000 has hidden %date% and %time% variables. You can "echo %date% %time%" and it will spit the current date/time.

![]() |
Norton Ghost disk (Dos) w...
|
The Doofus
|

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