Specifying date in robocopy destination folder

6,798

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:
6,798

Related videos on Youtube

Astron
Author by

Astron

Updated on September 18, 2022

Comments

  • Astron
    Astron almost 2 years

    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
    Astron almost 13 years
    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.
  • Nixphoe
    Nixphoe almost 13 years
    Command line you will need a single %, if you put it in a script you'll need to keep the double %%.
  • Kiquenet
    Kiquenet almost 10 years
    If you can use like this: for /f "delims=" %%a in (serversToUpdate.txt) do ?