0

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
    `robocopy` interprets the `\ `as an escape character, in particular to escape quotation marks (for whatever reason), so when the source or destination directory is enclosed within `""` and end with a backslash, the closing `"` is escaped (`\"`), so the next found `"` is actually taken as the closing one, hence leaving behind an odd/invalid command line; therefore, remove the trailing `\ `from both source and destination paths... – aschipfl Apr 09 '20 at 23:28
  • Hence, @aschipfl, the reason why I made that particular part of my answer, 10 hours earlier, emboldened. The OP however, is reporting that my answer which omits that trailing backslash fails in exactly the same way! So either they haven't tested my answer exactly as it was provided to them or … – Compo Apr 10 '20 at 11:53

2 Answers2

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.

Compo
  • 30,301
  • 4
  • 20
  • 32
  • For the source folder, it was a typo! – Dharti Sutariya Apr 09 '20 at 13:19
  • …but the trailing backslash wasn't, it was an error! How about some feedback instead? – Compo Apr 09 '20 at 13:21
  • getting the same error while running bat file using pipeline... – Dharti Sutariya Apr 10 '20 at 06:16
  • @DhartiSutariya, the errors aren't related to creating a directory with a date, and are therefore outside of the scope of my answer. My answer provides a solution to using robocopy to both determine the date in a consistent format, regardless of user/language/locale/PC and copy using it. The options for robocopy, your environment etc. are under your control. You have access to the entire output, we don't, you have potentially hundreds of combinations of options, yet you've used only one, `/V`. Please open a Command Prompt window, type `robocopy /?`, press enter, and read its usage information. – Compo Apr 10 '20 at 11:03
0

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.

Daniel Mann
  • 49,975
  • 11
  • 87
  • 105
  • I know there are tasks in azure DevOps server 2019, but I have one bat file which performs many tasks that are not provided by Azure DevOps server task list.... – Dharti Sutariya Apr 10 '20 at 06:15
  • Remove the Robocopy from your batch file, then? I don't see why that's an issue. – Daniel Mann Apr 10 '20 at 12:29
  • There is some logic, I don't want to remove this task from a bat file. what I want is need to create one folder with date and time... – Dharti Sutariya Apr 27 '20 at 04:02