Difference between xcopy and robocopy
Solution 1
Robocopy replaces XCopy in the newer versions of windows
- Uses Mirroring, XCopy does not
- Has a /RH option to allow a set time for the copy to run
- Has a /MON:n option to check differences in files
- Copies over more file attributes than XCopy
Yes i agree with Mark Setchell, They are both crap. (brought to you by Microsoft)
UPDATE:
XCopy return codes:
0 - Files were copied without error.
1 - No files were found to copy.
2 - The user pressed CTRL+C to terminate xcopy. enough memory or disk space, or you entered an invalid drive name or invalid syntax on the command line.
5 - Disk write error occurred.
Robocopy returns codes:
0 - No errors occurred, and no copying was done. The source and destination directory trees are completely synchronized.
1 - One or more files were copied successfully (that is, new files have arrived).
2 - Some Extra files or directories were detected. No files were copied Examine the output log for details.
3 - (2+1) Some files were copied. Additional files were present. No failure was encountered.
4 - Some Mismatched files or directories were detected. Examine the output log. Some housekeeping may be needed.
5 - (4+1) Some files were copied. Some files were mismatched. No failure was encountered.
6 - (4+2) Additional files and mismatched files exist. No files were copied and no failures were encountered. This means that the files already exist in the destination directory
7 - (4+1+2) Files were copied, a file mismatch was present, and additional files were present.
8 - Some files or directories could not be copied (copy errors occurred and the retry limit was exceeded). Check these errors further.
16 - Serious error. Robocopy did not copy any files. Either a usage error or an error due to insufficient access privileges on the source or destination directories.
There is more details on Robocopy return values here: http://ss64.com/nt/robocopy-exit.html
Solution 2
The most important difference is that robocopy
will (usually) retry when an error occurs, while xcopy
will not. In most cases, that makes robocopy
far more suitable for use in a script.
Addendum: for completeness, there is one known edge case issue with robocopy; it may silently fail to copy files or directories whose names contain invalid UTF-16 sequences. If that's a problem for you, you may need to look at third-party tools, or write your own.
Solution 3
The differences I could see is that Robocopy has a lot more options, but I didn't find any of them particularly helpful unless I'm doing something special.
I did some benchmarking of several copy routines and found XCOPY and ROBOCOPY to be the fastest, but to my surprise, XCOPY consistently edged out Robocopy.
It's ironic that robocopy retries a copy that fails, but it also failed a lot in my benchmark tests, where xcopy never did.
I did full file (byte by byte) file compares after my benchmark tests.
Here are the switches I used with robocopy in my tests:
**"/E /R:1 /W:1 /NP /NFL /NDL"**.
If anyone knows a faster combination (other than removing /E, which I need), I'd love to hear.
Another interesting/disappointing thing with robocopy is that if a copy does fail, by default it retries 1,000,000 times with a 30 second delay between each try. If you are running a long batch file unattended, you may be very disappointed when you come back after a few hours to find it's still trying to copy a particular file.
The /R and /W switches let you change this behavior.
- With /R you can tell it how many times to retry,
- /W let's you specify the wait time before retries.
If there's a way to attach files here, I can share my results.
- My tests were all done on the same computer and
- copied files from one external drive to another external,
- both on USB 3.0 ports.
I also included FastCopy and Windows Copy in my tests and each test was run 10 times. Note, the differences were pretty significant. The 95% confidence intervals had no overlap.
Solution 4
Its painful to hear people are still suffering at the hands of *{COPY} whatever the version. I am a seasoned batch and Bash script writer and I recommend rsync , you can run this within cygwin (cygwin.org) or you can locate some binaries floating around . and you can redirect output to 2>&1 to some log file like out.log for later analysing. Good luck people its time to love life again . =M. Kaan=
Solution 5
I have written lot of scripts to automate daily backups etc. Previously I used XCopy and then moved to Robocopy. Anyways Robocopy and XCopy both are frequently used in terms of file transfers in Windows. Robocopy stands for Robust File Copy. All type of huge file copying both these commands are used but Robocopy has added options which makes copying easier as well as for debugging purposes.
Having said that lets talk about features between these two.
Robocopy becomes handy for mirroring or synchronizing directories. It also checks the files in the destination directory against the files to be copied and doesn't waste time copying unchanged files.
Just like myself, if you are into automation to take daily backups etc, "Run Hours - /RH" becomes very useful without any interactions. This is supported by Robocopy. It allows you to set when copies should be done rather than the time of the command as with XCopy. You will see robocopy.exe process in task list since it will run background to monitor clock to execute when time is right to copy.
Robocopy supports file and directory monitoring with the "/MON" or "/MOT" commands.
Robocopy gives extra support for copying over the "archive" attribute on files, it supports copying over all attributes including timestamps, security, owner, and auditing information.
Hope this helps you.
tourist
Updated on July 05, 2020Comments
-
tourist almost 4 years
I'm kind of new to batch scripting. As a newbie I find both both of them useful while scripting What are the key differences between xcopy and robocopy?
-
Mark Setchell almost 10 yearsMuch more constructive than my answer, but far less fun :-)
-
foxidrive almost 10 years
copy
defaults to/b
on binary files now. I'm not sure where you get your hatred of robocopy from... your link just shows that thearchive
attribute is being utilised as it is designed. -
Harry Johnston over 9 yearsRobocopy works perfectly well up to and including Windows 7. If it has been broken in Windows 8 ... well, that doesn't actually surprise me much. Maybe Windows 10 will be better.
-
Gerald Combs about 9 yearsNote that XCopy returns a standard exit code (zero on success, nonzero on failure) while Robocopy does not.
-
Mark Cooper almost 9 yearsCan you be a little more constructive and suggest an alternative please?
-
Mark Setchell almost 9 years@MarkCooper Yes, either install Linux or install VirtualBox and put Linux on the VirtualBox then use
rsync
orcp
. -
Mark Cooper almost 9 years@MarkSetchell Terrible answer. Judging by your rep you should know better.
-
Mark Setchell almost 9 years@MarkCooper The answer addresses the question which, to remind you, asked about "the differences" not to recommend an alternative. My answer is that there is little difference because both tools are poor - and I stand by that answer. If you have a different question, please ask it as a new one instead of piggybacking off other people's questions.
-
Mark Cooper almost 9 years@MarkSetchell you have not answered OP's question, instead giving your own opinion about how much you dislike XCOPY and ROBOCOPY. This isn't fact, it isn't constructive and does nothing to help OP.
-
OK999 over 8 yearsi don't see this answer as
hatred
. I see humor in it. And god knows why there have to be 3 versions of a command that does copy function. copy, xcopy & robocopy... why not build on the single copy? For any new block to windows world of scripting. this is making a steep learning curve unlike the shell programming. -
Harry Johnston about 8 years@OK9999: it makes sense once you know the history. Both
copy
andxcopy
were part of DOS, and they had to be separate becausecopy
was an internal command andxcopy
an external one. Windows included them both for backwards compatibility. Therobocopy
command was originally developed by a separate team, initially for internal use and later as part of the resource kit. It didn't become a built-in part of Windows until later on. (I'm also dubious about the claim that shell programming doesn't have a steep learning curve. The syntax is pretty darned abtruse!) -
Dan Solovay almost 8 yearsCan you link to documentation that describes this behavior?
-
Xander Luciano over 7 yearsYou answer is a little difficult to read, you should format it a bit more. You can use ` for
inline
code ` (its the squiggle/tilde key that looks like this: ~) and enter twice for a new paragraph. -
SixSigmaGuy over 7 yearsSorry, When I wrote it, it had blank lines to separate things.
-
Luke almost 6 yearsis there any (free and/or open source) better solution for auto backup files in a windows server to another windows server? My Company has too much windows server, and they don't give me money to buy any license for this task.
-
Olivier Pons over 5 yearsI can tell you one f..kin big difference I've just had 3 minutes ago: you go to a directory on your network. Shift-Right click "open powershell here". Then try "
robocopy "." "D:\tmp\" /MOV
" (D:
is a physical hard drive). This work. Turn off the computer that shares that directory (while copying). This won't work with tons of errors, press CTRL-C and try again.robocopy
has tried to move all the files from theC:\Windows\System32
directory. True. You can't do that withxcopy
. -
Olivier Pons over 5 yearsWith what I've just had I'll never use
robocopy
again. Never ever. Not safe at all. Microsoft should finish properly such programs before releasing it. You copy from the network, the network is down, then it tries to move files from where it is and... it'sC:\Windows\System32
. Good job Microsoft, after 20 years still not able to make a program that moves properly files. I'll show this example to my students so they'll understand why they have to go to Linux. -
Harry Johnston over 5 years@OlivierPons, I've been using robocopy for twenty years and never had any problems. Certainly it has never copied files to or from the wrong place! Can you explain in more detail what you think went wrong and how to reproduce it?
-
Olivier Pons over 5 yearsSo in 20 years you've just never had network problems while copying. You're lucky, end of story. And read all comments and answers about
xcopy
vsrobocopy
... they talk by themselves. -
Olivier Pons over 5 yearsOr go for Linux forever as well. Better choice IMHO.
-
Harry Johnston over 5 years@OlivierPons, of course I have - that's the whole point of using robocopy, because it keeps going after a network glitch instead of stopping dead.
-
Harry Johnston over 5 years... for completeness, there is one known issue with robocopy when dealing with filenames that contain invalid UTF-16 sequences, but that's likely to be an issue with most third-party tools as well. I'll add a note to my answer anyway. (And as already mentioned, your problem was probably caused by Powershell rather than by robocopy. Microsoft's fault either way, of course.)
-
Harry Johnston over 5 years@OlivierPons, I can repro. Definitely a bug in Powershell, the same thing happens with any external command, not just robocopy. That means it isn't really relevant to this question because the OP is programming in batch, not in Powershell, but if you must use Powershell then you could use its Copy-Item or Move-Item cmdlets instead of external tools, or you could give robocopy the fully qualified path.
-
Olivier Pons over 5 yearsSorry for being angry, but after more than 20 years, still not being able to make a command-line utility that moves files safely in totally un-professional. Linux for the win.
-
Olivier Pons over 5 yearsSorry for being angry, but after more than 20 years, still not being able to make a command-line utility that moves files safely in totally un-professional. Linux for the win.
-
Harry Johnston over 5 years@OlivierPons, understandable, I just wanted to clarify that the problem wasn't in robocopy so using a third-party command-line tool wouldn't help. As for the Powershell issue, I've filed a bug report, but I'm not going to hold my breath.
-
98percentmonkey over 5 yearsAfter 2-3 with Robocopy which looks good at first, I'll try rsync. Robocopy has horrible issues, the summary is totally wrong, the default value for multi-threading is mostly totally wrong/slow for all stuff i copied, resume didn't work. Just take a look at the github repo and the issue, it's far from a good product. It even overwrites System Volume Info and the recovery dir and destroys the drives. Unbelievable.
-
Harry Johnston over 4 yearsFor the benefit of future readers, Olivier's problems were caused by Powershell, not Robocopy.
-
SRR over 3 yearsWhen you use /RH does that mean the command will always run at that time without any interaction, even after restart?
-
Spencer almost 3 yearsI had a lot of problems with ROBOCOPY failing because people used to delete user accounts from Active Directory when they left the company, and their SIDs were the owners of some files or in their DACLs. Whenever robocopy hit such a file it would crash. It was a nightmare.