Re: calling xcopy from vbs file?

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: Phil Robyn [MVP] (zipprobyn_at_berkeley.edu)
Date: 03/25/04


Date: Thu, 25 Mar 2004 14:46:00 -0800

Bonj wrote:

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

>
> "Phil Robyn [MVP]" <zipprobyn@berkeley.edu> wrote in message
> news:%23is$yVrEEHA.2768@tk2msftngp13.phx.gbl...
>
>>Bonj wrote:
>>
>>
>>>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?
>>
>>
>>
>>>"Phil Robyn [MVP]" <zipprobyn@berkeley.edu> wrote in message
>>>news:ujWuUoTEEHA.2076@TK2MSFTNGP09.phx.gbl...
>>>
>>>
>>>>John Smith wrote:
>>>>
>>>>
>>>>
>>>>>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%
>>>>
>>>>--
>>>>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
>>>
>>>
>>>
>>
>>--
>>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
>
>
>

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


Relevant Pages

  • Re: More VB/Access/SQL syntax problems
    ... formatting it as a U.S. style mm/dd/yyyy date. ... which is a date and the format 101 is U.S. format mm/dd/yyyy. ... you'll notice the original SQL 2005 syntax shows ... Tony K. ...
    (microsoft.public.dotnet.languages.vb)
  • Re: calling xcopy from vbs file?
    ... You're right in that the date format on a particular machine might determine ... is 'mm/dd/yyyy' rather than 'Day mm/dd/yyyy', ... 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 ...
    (microsoft.public.scripting.vbscript)
  • RE: Simple Date Display Question
    ... have a spreadsheet with thousands of dates, all entered in mm/dd/yyyy format. ... matter what I do in this spreadsheet, they display as five digit numbers. ...
    (microsoft.public.excel.misc)
  • Re: validating a date
    ... >mm/dd/yyyy without any letters and only use the slashes. ... The text box would display the date/time ... by specifying the format property or function. ...
    (microsoft.public.access.modulesdaovba)
  • Re: dates in query HELP PLEASE!
    ... Regardless of what your regional settings have the short date format set to, ... date to mm/dd/yyyy format if that makes sense. ... > Then I append the where string to the rest of the SQL string, in order to> run it later. ...
    (microsoft.public.access.forms)