[Date Prev][Date Next][Subject Prev][Subject Next][ Date Index][ Subject Index]

Off-Topic: Xcopy /D:



Mimi's comment about DOS diehards led me to think some members of this
list might be interested in the following.

A while back I was trying to automate the writing of batch files to
archive each week's work at a client's. Robert Holmgren very graciously
supplied a VB Script to handle the job, and it worked very well (of
course). But then I realized that archive bits, on which the Xcopy /M
routine that I was using depends, can be flipped in various ways, and I
decided to see if I could switch back to using the /D: switch, which
XCopies everything created or modified after the specified date.

After looking at--and borrowing heavily from--Robert's code, consulting a
book, and doing a great deal of trial-and-error testing, I got what I
needed, but discovered something interesting: in Win 95 and the original
release of 98, a command to, e.g.,
Xcopy c:\*.wpd f: /S /D:06-28-04
whether given from the DOS prompt or from a batch file, causes ALL files
matching the spec, not just those created or modified since 6/28/04, to
be copied. At first it looked as if Xcopy was just ignoring the date
switch if the year had only two digits (/D:06-28-2004 worked fine). Then
I realized that it was the old Y2K bug: XCopy was interpreting 06-28-04
as June 28, 1904, and of course everything on my PC (and every other
computer in the world) was later than that. Hard to believe that in 1998
even Redmond would let that slip by. Win 98 Second Edition interprets
6-28-04 correctly.

A further gotcha is that VB Script's default date format appears to have
only two digits in the year. Thus the following code produces a batch
file that does not run correctly under Win 95 or 98A (which are what
we're using in the office):

dim d,o,t
t=date
set o=CreateObject("Scripting.FileSystemObject")
set d=o.CreateTextFile("c:\VBSAND~1\xcbydate.BAT",True,False)
d.WriteLine "@echo off"
D.Writeline "Xcopy C:\*.wpd d: /S /D:"&t
D.Close
Wscript.Quit(0)

The resulting batch file reads

echo off
xcopy c:\*.wpd /s /d:6-30-04

Fortunately, VB Script does have functions for winkling out the day,
month, and year from a date, and the resulting year has four digits.
Hence the following works:

dim d,o,t,dt,mt,yt
t=date
dt=day(t)
mt=month(t)
yt=year(t)
t=mt&"/"&dt&"/"&yt
set o=CreateObject("Scripting.FileSystemObject")
set d=o.CreateTextFile("c:\VBSAND~1\xcbydate.BAT",True,False)
d.WriteLine "@echo off"
d.WriteLine "xcopy c:\*.wpd d: /s /d:"&t
d.Close
WScript.Quit(0)

The resulting batch files reads

@echo off
xcopy c:\*.wpd d: /s /d:6/30/2004

And works, even under 98A.

Patricia