1

When using robocopy windows utility, what flags do I set so that robocopy aborts on the very first error it sees, similar to xcopy /dry command?

I need to mirror two dirs, and on occasion some files would be locked. I do not want robocopy to continue trying to copy files, or override the files that are not locked - rather the very first error should stop the whole copy process.

Yuri Astrakhan
  • 151
  • 1
  • 7

3 Answers3

1
Robocopy "C:\Source\" "C:\Destination\" *.* /V /S /E /COPY:DAT /R:1 /W:0 > log.txt

Output:

Source : C:\Source\  
Dest : C:\Destination\  
Files : \*.*  
Options : \*.* /V /S /E /COPY:DAT /R:1 /W:0
...

The /R:1 option sets the retry attempts to 1 and the /W:0 sets the wait time to 0. Other options that I used were:

  • /S Copy subfolders
  • /E Copy subfolders, even empty ones
  • /V Produce verbose output showing skipped files, errors, etc.
  • /COPY:DAT Copy data, attributes and time stamps which is the default anyways
  • > log.txt Pipes output to a text file for later inspection.
jscott
  • 24,204
  • 8
  • 77
  • 99
Mark A
  • 161
  • 6
1

I think you're not going to find an easy way to do this with Robocopy alone - it doesn't have a switch to exit on failures.

Xcopy is a lot less capable but by default it does fail in the way you want as you've pointed out. What you could do is run XCopy and if it terminates with errorlevel 0 (success) then you could then run Robocopy to carry out the purge function. This isn't going to deal cleanly with some edge cases, but it will behave the way you want for the most part.

Helvick
  • 19,579
  • 4
  • 37
  • 55
1

You're going to have to use a batch file and robocopy exit codes

GregD
  • 8,713
  • 1
  • 23
  • 35