문제 설명
robocopy 명령으로 타임 스탬프를 사용하여 날짜와 시간으로 폴더를 만드는 방법 (How to create folder with date and time using timestamp with robocopy command)
다음 타임스탬프를 사용하여 폴더를 만들고 싶습니다. %DATE:/=‑%_%TIME::=‑%
내 Robocopy 명령은 다음과 같습니다.
ROBOCOPY "%BUILD_SOURCESDIRECTORY%\sourcefolder\" "\\server\destination\%date:/=‑%_%time::=‑%" /V
하지만 작동하지 않고 오류가 발생합니다.
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)
참고: 아래 링크를 참조했지만 날짜로 폴더를 만들고 싶습니다. 및 시간. 이 링크에는 날짜 스탬프만 언급되어 있습니다.
Robocopy를 사용하여 명령줄에서 TimeStamp로 파일을 복사하는 방법
누군가에 대한 아이디어가 있는 경우 , 알려주세요.
참조 솔루션
방법 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.
(by Dharti Sutariya、Compo、Daniel Mann)