xcopy和robocopy之间的区别

时间:2014-06-09 13:09:58

标签: windows batch-file batch-processing

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

5 个答案:

答案 0 :(得分:60)

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

  1. 使用镜像,XCopy不
  2. 具有/ RH选项以允许运行副本的设定时间
  3. 有/ MON:n选项来检查文件中的差异
  4. 复制比XCopy更多的文件属性
  5. 是的我同意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.
    

    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.
    

    此处有关于Robocopy返回值的更多详细信息:http://ss64.com/nt/robocopy-exit.html

答案 1 :(得分:13)

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

附录:为了完整性,robocopy存在一个已知的边缘案例问题; it may silently fail to copy files or directories whose names contain invalid UTF-16 sequences.如果您遇到问题,可能需要查看第三方工具,或自行编写。

答案 2 :(得分:2)

听到人们仍然在痛苦的手中感到痛苦 * {COPY}无论版本如何。 我是一个经验丰富的批处理和Bash脚本编写者,我推荐rsync,你可以在cygwin(cygwin.org)中运行它,或者你可以找到一些浮动的二进制文件。 并且您可以将输出重定向到2&gt;&amp; 1到某些日志文件,例如out.log,以便以后分析。 祝你好运的人再次热爱生活。 = M。卡安=

答案 3 :(得分:1)

我写了很多脚本来自动执行日常备份等。以前,我使用XCopy,然后转移到Robocopy。无论如何,就Windows中的文件传输而言,Robocopy和XCopy都经常使用。 Robocopy代表“健壮的文件复制”。这两种命令都可以使用所有类型的大文件复制功能,但是Robocopy添加了一些选项,这些选项使复制变得更容易以及用于调试目的。

话虽如此,让我们谈谈这两者之间的功能。

  • Robocopy可以方便地用于镜像或​​同步目录。它 还要对照文件检查目标目录中的文件 进行复制,而不会浪费时间复制未更改的文件。

  • 就像我一样,如果您要进行自动化以进行每日备份 等等,“运行时间-/ RH”在没有任何交互的情况下非常有用。 Robocopy支持此功能。它允许您设置复印时间 应该完成而不是像使用XCopy那样执行命令的时间。您 它将在任务列表中看到robocopy.exe进程,因为它将运行 监视时钟以便在正确复制时间时执行时钟的背景。

  • Robocopy支持使用“ / MON”或“ / MON”监视文件和目录 “ / MOT”命令。

  • Robocopy为复制“存档”属性提供了额外的支持 在文件上,它支持复制所有属性,包括 时间戳,安全性,所有者和审核信息。

希望这对您有所帮助。

答案 4 :(得分:-7)

他们都是垃圾! XCOPY较旧且不可靠,因此Microsoft将其替换为ROBOCOPY,这仍然是垃圾。

http://answers.microsoft.com/en-us/windows/forum/windows_8-files/robocopy-appears-to-be-broken-in-windows-8/9a7634c4-3a9d-4f2d-97ae-093002a638a9

但是,不要担心,这是一个长期的传统,它始于最初的COPY命令,直到今天仍然需要/B切换才能实现它正确复制!