1

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.

Astron
  • 377
  • 4
  • 16

2 Answers2

3

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.

Nixphoe
  • 4,524
  • 7
  • 32
  • 51
  • 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 02:58
  • 2
    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 03:48
0

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
)
Frederik
  • 3,293
  • 3
  • 30
  • 46