Automate Log output from Batch File

G

Guest

I have written a small batch file to copy two directories for me, but I would
like the output i.e Backup.log to be a unique file name, preferably something
like todaysdate.log. can anyone help ?

@Echo Off
@Echo "Backing Directories - Please Wait"
E:
xcopy oaccounts Z:\oaccounts /E/I/Y/F >z:\Backup.log
xcopy opendbcopy Z:\opendbcopy /E/I/Y/F >>z:\Backup.log
@Echo "Finished"
@echo on

Thanks
 
B

billious

gibbylinks said:
I have written a small batch file to copy two directories for me, but I
would
like the output i.e Backup.log to be a unique file name, preferably
something
like todaysdate.log. can anyone help ?

@Echo Off
@Echo "Backing Directories - Please Wait"
E:
xcopy oaccounts Z:\oaccounts /E/I/Y/F >z:\Backup.log
xcopy opendbcopy Z:\opendbcopy /E/I/Y/F >>z:\Backup.log
@Echo "Finished"
@echo on

Thanks

If, at the prompt, you type

echo %date%

you will see the date echoed to the screen. Since I don't know what
PARTICULAR date-format you use, all I can do is show you a formula.

echo %date:~m,n%

will show the n characters of %date% starting at the m'th - where the first
character is "m=0"

Suppose your date format is

Mon 09-19-2005

then
%date:~4,2% will show the "09"
%date:~7,2% will show the "19"
%date:~10,4% will show the "2005"
%date:~12,2% will show the "05"

So, in your batch, if you want your logfile named "backupYYMMDD.log" (which
shows the backup names conveniently listed in date-order) you could change

z:\Backup.log

to

z:\Backup%date:~12,2%%date:~4,2%%date:~7,2%.log

to produce "z:\Backup050919.log" for today.

You can pull the same trick with %TIME% if you wish. Just don't try to
include "/" or ":" in the filename.

For more info on NT/2K/XP batch, see alt.msdos.batch.nt - a long-established
newsgroup dedicated to NT+-batch methods.

HTH

....Bill
 
T

Torgeir Bakken \(MVP\)

gibbylinks said:
I have written a small batch file to copy two directories for me, but I would
like the output i.e Backup.log to be a unique file name, preferably something
like todaysdate.log. can anyone help ?

@Echo Off
@Echo "Backing Directories - Please Wait"
E:
xcopy oaccounts Z:\oaccounts /E/I/Y/F >z:\Backup.log
xcopy opendbcopy Z:\opendbcopy /E/I/Y/F >>z:\Backup.log
@Echo "Finished"
@echo on

Thanks
Hi,

--------------------8<----------------------
@echo off

setlocal
echo D = Now : WScript.Echo Year(D) ^& _ >%tmp%\today.vbs
echo Right(100+Month(D),2) ^& Right(100+Day(D),2) >>%tmp%\today.vbs

for /f "tokens=1" %%a in (
'cscript.exe //Nologo %tmp%\today.vbs') do set today=%%a

del %tmp%\today.vbs

set logfile="z:\Backup_%today%.log"

@Echo "Backing Directories - Please Wait"
E:
xcopy oaccounts Z:\oaccounts /E/I/Y/F >%logfile%
xcopy opendbcopy Z:\opendbcopy /E/I/Y/F >>%logfile%
@Echo "Finished"
endlocal

--------------------8<----------------------
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top