G

Guest

Guest
Archived from groups: microsoft.public.windowsxp.general (More info?)

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
 
G

Guest

Guest
Archived from groups: microsoft.public.windowsxp.general (More info?)

gibbylinks wrote:

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



--
torgeir, Microsoft MVP Scripting and WMI, Porsgrunn Norway
Administration scripting examples and an ONLINE version of
the 1328 page Scripting Guide:
http://www.microsoft.com/technet/scriptcenter/default.mspx
 
G

Guest

Guest
Archived from groups: microsoft.public.windowsxp.general (More info?)

"gibbylinks" <gibbylinks@discussions.microsoft.com> wrote in message
news:4A0CE758-FC5C-44D8-8BDC-57B31AEA7D43@microsoft.com...
>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