Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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
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
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
If you can use like this: for /f "delims=" %%a in (serversToUpdate.txt) do ? – Kiquenet Sep 26 '14 at 10:44

Your Answer


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.