.bat file to copy files using current date as part of name?

B

+Bob+

I need to set up a bat file that will use xcopy to copy a directory
from one drive to another. The resulting directory needs to
incorporate the date that it is copied into the name. Something like
this:

xcopy c:\bigdir\*.*/s/e d:\bigdir-10-oct-2008\*.*

I need to do this on a regular basis, so how can I pull the date
within the bat file into a variable?

Also, assuming I can get the date into a variable named something like
"DateIn" will a command like this work:

xcopy c:\bigdir\*.*/s/e d:\bigdir-%DateIn%\*.*

Thanks,
 
B

+Bob+

Another link offers the following code which is similar to the last link
there -

for /f "tokens=2-4 delims=/ " %%i in ('date/t') do (
(set Dy=%%i)
(set Mth=%%j)
(set Yr=%%k)
)
I've modified the last line of his code below to show how to name your
directory.

mkdir c:\%Dy%-%Mth%-%Yr%

This assumes you want it on the C drive, change the drive and pathname
to what you need.

Thanks Boys, this got me where I needed to go.
 
B

+Bob+

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

Terry:

It seems to throw an error on this line. I don't know enough about
windows scripting to diagnose it.
 

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

Similar Threads


Top