How to append date to directory path in xcopy

前端 未结 4 1421
不思量自难忘°
不思量自难忘° 2021-01-14 18:41

I do have a xcopy statement in bat file.. would you please help me to append today\'s date to one of directories in destination xcopy /S /E /I %sourceFolder% \"C:\\Shared\\

4条回答
  •  余生分开走
    2021-01-14 19:08

    Just use %date% in your command:

    xcopy /S /E /I %sourceFolder% "C:\Shared\copy\copy-%date%"
    

    Note: this will keep the date in the original format.

    Assuming your local date format is Fri 06/07/2013 you can format it into 06072013 by cutting up the string like this:

    %date:~4,2%%date:~7,2%%date:~10,4%
    

    So the final command will be:

    xcopy /S /E /I %sourceFolder% "C:\Shared\copy\copy-%date:~4,2%%date:~7,2%%date:~10,4%"
    

提交回复
热议问题