Simple batch file problem

Associate
Joined
20 Jan 2004
Posts
1,379
Hi guys

Trying to create a batch file to copy a whole directory to a location on another server.

I also need it to name the folder the current date.

In its current state it does copy the contents but it just dumps it in the folder without creating the dated folder correctly.

Heres the text :

xcopy /e /h /y \\legolas\hal_r \\manfriday\backup\legolas_backup_20092609

for /f "tokens=1-5 delims=/ " %%d in ("%date%") do rename "\\legolas\hal_r" %%d-%%e-%%f-%%g



If anyone can tell me where I went wrong I'll love them forever!

Thanks. :)
 
Erm, someone who's better at this then me will probably be more use.

But firsty I'm not sure you can use rename, I think the command is ren, and also try it with a mapped drive letter. Not all commands in batch work with UNC paths.
 
Should be as simple as:

xcopy /e/h/i/y \\legolas\hal_r \\manfriday\backup\legolas_backup_%date:/=%

Only thing is that'll give today's date as 21112009.
 
Should be as simple as:

xcopy /e/h/i/y \\legolas\hal_r \\manfriday\backup\legolas_backup_%date:/=%

Only thing is that'll give today's date as 21112009.

If you wanted it in the same format as you stating in OP, you could just declare 3 variables for the date and set the characters to use:

set Day=%date:~0,2%
set MonthNum=%date:~3,2%
set Year=%date:~6,4%

Then you could use the above but just use the variables to construct the format that you want:

xcopy /e/h/i/y \\legolas\hal_r \\manfriday\backup\legolas_backup_%Year%%MonthNum%%Day%

That should construct with the date format of "20091124".
 
beware that the date command outputs different depedning on the PC locale/region/preferences set in the control panel. Could be an issue if running this on different PCs that are configured slightly differently
 
Back
Top Bottom