calling xcopy from vbs file?

  • Thread starter Thread starter John Smith
  • Start date Start date
J

John Smith

I want to be able to create a batch file that will run daily and only move
files from c:\folder1 to c:\folder2 that contain today's date.

xcopy c:\folder1 c:\folder2 /d:3-12-2004

the above will work if I hard-code the date, but I need to be able to have
the current date. So, I tried to create a .vbs that would call the xcopy
after I put together the date:
-----------------------------------
test.vbs:

dim dDate
dim sString
Dim WshShell, oExec

dDate = FormatDateTime(Now, 2)

Set WshShell = CreateObject("WScript.Shell")
sString = "test.bat " & CStr(dDate)
Set oExec = WshShell.Exec(sString)
 
John said:
dDate = FormatDateTime(Now, 2)

Set WshShell = CreateObject("WScript.Shell")
sString = "test.bat " & CStr(dDate)
Set oExec = WshShell.Exec(sString)
-----------------------------------------
test.bat

xcopy c:\test1 c:\test2 /d:%1
---------------------------------

This doesn't work. I can run test.bat 3/12/2004 from the command
line and it works fine. but not the test.vbs.
Does anyone have any suggestions???
Hi


dDate = FormatDateTime(Now, 2)

Set WshShell = CreateObject("WScript.Shell")
sCmd = "test.bat " & CStr(dDate)
WshShell.Run sCmd, 1
 
John said:
I want to be able to create a batch file that will run daily and only move
files from c:\folder1 to c:\folder2 that contain today's date.

xcopy c:\folder1 c:\folder2 /d:3-12-2004

the above will work if I hard-code the date, but I need to be able to have
the current date. So, I tried to create a .vbs that would call the xcopy
after I put together the date:
-----------------------------------
test.vbs:

dim dDate
dim sString
Dim WshShell, oExec

dDate = FormatDateTime(Now, 2)

Set WshShell = CreateObject("WScript.Shell")
sString = "test.bat " & CStr(dDate)
Set oExec = WshShell.Exec(sString)
-----------------------------------------
test.bat

xcopy c:\test1 c:\test2 /d:%1
---------------------------------

This doesn't work. I can run test.bat 3/12/2004 from the command line and it
works fine. but not the test.vbs.
Does anyone have any suggestions???

In this case, you really don't need test.vbs.


xcopy c:\test1 c:\test2 /d:%date:~4%
 
John Smith said:
I want to be able to create a batch file that will run daily and only move
files from c:\folder1 to c:\folder2 that contain today's date.

xcopy c:\folder1 c:\folder2 /d:3-12-2004
You could also use xxcopy. www.xxcopy.com (Free for pivate use)

the option /DA#0 or /DA:. will do without any calculations.
 
Would that work in October?

Phil Robyn said:
In this case, you really don't need test.vbs.


xcopy c:\test1 c:\test2 /d:%date:~4%

--
Phil Robyn
Univ. of California, Berkeley

u n z i p m y a d d r e s s t o s e n d e - m a i l
 
If you just pass the /D switch without anything after it, then it will only
copy files that are newer than the target.
 
Bonj said:
Would that work in October?

Would *what* work in October? If you mean

xcopy c:\test1 c:\test2\ /d:%date:~4%

then of course it will work in October. Why wouldn't
it work in October?
 
well, if %date% is
31/10/2003
then %date:~4% is
0/2003
??
But I've just realised it would be in mm/dd/yyyy format not dd/mm/yyyy
format. So it would work in every month but only on the first to ninth
days....
 
Bonj said:
well, if %date% is
31/10/2003
then %date:~4% is
0/2003
??
But I've just realised it would be in mm/dd/yyyy format not dd/mm/yyyy
format. So it would work in every month but only on the first to ninth
days....

You're right in that the date format on a particular machine might determine
whether it would work or not. On both my Win2000 box and my WinXP box, the
format of %date% is


C:\cmd>echo %date%
Thu 03/25/2004

so '%date:~4%' will always be 'mm/dd/yyyy' regardless of what month
it happens to be (including October :-)).

If you have your machine so configured that the output of 'echo %date%'
is 'mm/dd/yyyy' rather than 'Day mm/dd/yyyy', then simply use

xcopy c:\test1 c:\test2\ /d:%date%

instead of

xcopy c:\test1 c:\test2\ /d:%date:~4%

YMMV.

Of course, %date% is not available in WinNT 4.0.
 
Back
Top