xcopy和robocopy之间的区别

nav*_*rri 49 windows batch-file batch-processing

我是批处理脚本的新手.作为一个新手,我发现在脚本编写时它们都很有用xcopy和robocopy之间的主要区别是什么?

Nic*_*ler 62

Robocopy在较新版本的Windows中取代了XCopy

  1. 使用镜像,XCopy不会
  2. 有一个/ RH选项,允许设置复制时间
  3. 有一个/ MON:n选项来检查文件中的差异
  4. 复制比XCopy更多的文件属性

是的,我同意Mark Setchell,他们都是废话.(由微软带给你)


更新:

XCopy返回码:

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.
Run Code Online (Sandbox Code Playgroud)

Robocopy返回代码:

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.
Run Code Online (Sandbox Code Playgroud)

有关Robocopy返回值的更多详细信息,请访问:http://ss64.com/nt/robocopy-exit.html

  • 请注意,XCopy返回标准退出代码(成功时为零,失败时为非零),而Robocopy则不然. (6认同)
  • 比我的回答更有建设性,但没那么有趣:-) (2认同)

Har*_*ton 13

最重要的区别在于robocopy(通常)在发生错误时重试,而xcopy不会.在大多数情况下,这robocopy更适合在脚本中使用.

附录:为了完整性,robocopy存在一个已知的边缘案例问题; 它可能无法复制名称包含无效UTF-16序列的文件或目录. 如果这对您来说是个问题,您可能需要查看第三方工具,或编写自己的工具.

  • 为了未来读者的利益,[Olivier 的问题是由 Powershell 而不是 Robocopy 引起的](/sf/ask/1688473251/ Between-xcopy-and-robocopy/24132239#comment90581885_24121244)。 (2认同)

Six*_*Guy 7

我可以看到的区别是Robocopy有很多选择,但是除非我做特别的事情,否则我发现其中没有什么特别有用。

我对几个复制例程进行了一些基准测试,发现XCOPY和ROBOCOPY是最快的,但是令我惊讶的是,XCOPY始终领先于Robocopy。

具有讽刺意味的是,robocopy重试失败的副本,但是在我的基准测试中,它也失败了很多,而xcopy却没有。

在基准测试后,我做了完整文件(逐字节)比较。

这是我在测试中与robocopy一起使用的开关:

 **"/E /R:1 /W:1 /NP /NFL /NDL"**.  
Run Code Online (Sandbox Code Playgroud)

如果有人知道更快的组合方式(除了需要删除/ E之外),我很想听听。

robocopy的另一个有趣/令人失望的事情是,如果副本确实失败,则默认情况下它将重试1,000,000次,每次尝试之间的间隔为30秒。如果您正在运行一个无人值守的长批处理文件,则在几个小时后再次回来发现它仍在尝试复制特定文件时,您可能会非常失望。

使用/ R和/ W开关可以更改此行为。

  • 使用/ R,您可以告诉它重试多少次,
  • / W让您指定重试之前的等待时间。

如果可以在此处附加文件,我可以共享结果。

  • 我的测试都是在同一台计算机上完成的,
  • 将文件从一个外部驱动器复制到另一个外部驱动器,
  • 都在USB 3.0端口上。

我还在测试中包括了FastCopy和Windows Copy,每个测试运行了10次。请注意,差异非常明显。95%的置信区间没有重叠。