How to create folder with date and time using timestamp with robocopy command [duplicate]

跟風遠走 提交于 2020-05-17 06:54:09

问题


I want to create a folder using this Timestamp: %DATE:/=-%_%TIME::=-%

My Robocopy command is :

ROBOCOPY "%BUILD_SOURCESDIRECTORY%\sourcefolder\" "\\server\destination\%date:/=-%_%time::=-%" /V

but it is not working, getting an error:

2020-04-07T03:53:21.7269608Z ##[error]Process completed with exit code 1.
2020-04-07T03:53:21.7292925Z ##[debug]System.Exception: Process completed with exit code 1.
at Microsoft.VisualStudio.Services.Agent.Worker.Handlers.ProcessHandler.RunAsync()
at Microsoft.VisualStudio.Services.Agent.Worker.TaskRunner.RunAsync()
at Microsoft.VisualStudio.Services.Agent.Worker.StepsRunner.RunStepAsync(IStep step, CancellationToken jobCancellationToken)

Note: I referred to the below link but I want to create a folder with date and time.in this link only date stamp mentioned.

How to use Robocopy to copy files with TimeStamp in command line

if anyone has an idea about, please let me know.


回答1:


Here's a single line for your batch file, which should do as you need.

Please note that when you input your real source path, spell it correctly, (sourcefolder, not sorcefolder), and ensure that it doesn't have a trailing backslash. The same is true for your destination.

@For /F "Tokens=1-6Delims=/: " %%G In ('""%__AppDir__%Robocopy.exe" \: . /NJH /L|"%__AppDir__%find.exe" " 123""')Do @"%__AppDir__%Robocopy.exe" "%BUILD_SOURCESDIRECTORY%\sourcefolder" "\\server\destination\%%G-%%H-%%I_%%J-%%K-%%L" /V

Obviously, the server path must be mounted/available and the user must have the required permissions for the task too.




回答2:


Use the Publish Build Artifacts task to publish build artifacts. Use the Windows Machine File Copy task to copy files to a remote Windows machine.

There is no reason to manually copy files with Robocopy.



来源:https://stackoverflow.com/questions/61119809/how-to-create-folder-with-date-and-time-using-timestamp-with-robocopy-command

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!