Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I would like to specify the date via CLI when running robocopy so that the destination folder includes the date.

robocopy C:\folder\ Z:\folder_DATE /E /ZB /COPYALL /NP /V /LOG:F:\backup_log.txt

Where DATE is the current date. Is this possible or would I have to resort to power shell?

I found this Stack Overflow article but am looking to keep it simpler.

share|improve this question

2 Answers 2

up vote 3 down vote accepted

You didn't really say what the format of the date you wanted, so I'm going by yyyymmdd. That'll probably suit sorting better as the days, months and years go on.

FOR /F "tokens=2-4 delims=/ " %%a in ('echo %date%') DO SET datevar=%%c%%b%%a
robocopy C:\folder\ Z:\folder_%datevar% /E /ZB /COPYALL /NP /V /LOG:F:\backup_log.txt

You can change the date however you want with the %%c being the year %%b being the month and %%a being the day. Just reorder them to your need.

share|improve this answer
    
The format you suggested is fine and thanks for the explanation. I am getting the following error when entering the first line %%a was unexpected at this time. –  Astron Jul 27 '11 at 2:58
1  
Command line you will need a single %, if you put it in a script you'll need to keep the double %%. –  Nixphoe Jul 27 '11 at 3:48
    
Thanks for the clarification! –  Astron Jul 27 '11 at 15:50

Here's my suggestion:

FOR /F "tokens=1,2,3 delims=/ " %%A in ('date /T') DO (
robocopy C:\folder\ Z:\folder_%%A-%%B-%%C /E /ZB /COPYALL /NP /V /LOG:F:\backup_log.txt
)
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.