xcopy:移动文件而不是复制?

JBu*_*ace 14 windows-7 xcopy

我想使用xcopy验证标志通过网络移动文件,而不是复制文件。我找不到 xcopy 上的开关来移动文件,xmove我可以使用它verify吗?

目前我正在使用,xcopy /D /V只有在验证文件已成功复制到目标时才需要删除源中的文件。

imt*_*man 11

你应该看看robocopy,它比xcopy. 您可以使用/MOV或轻松移动文件/MOVE

仅移动文件(复制后从源中删除)

robocopy from_folder to_folder files_to_copy /MOV
Run Code Online (Sandbox Code Playgroud)

移动文件和目录(复制后从源中删除)

robocopy from_folder to_folder files_to_copy /MOVE
Run Code Online (Sandbox Code Playgroud)

http://ss64.com/nt/robocopy.html

  • 据我所知,Robocopy 没有“验证”。 (2认同)
  • 如果它被移动,但文件大小不匹配会发生什么?这就是为什么我需要做一个“验证”。我在 robocopy 信息中没有看到任何内容表明它实际上验证了两个文件大小以确保它不仅被移动而且被正确移动。 (2认同)

Ƭᴇc*_*007 2

您可以使用批处理文件来运行Xcopy带有验证的命令,然后检查 Xcopy 返回的错误级别以确定文件复制是否成功。如果他们这样做了,请删除源。

来自Xcopy 文档

Exit
code  Description
====  ===========
  0   Files were copied without error.
  1   No files were found to copy.
  2   The user pressed CTRL+C to terminate xcopy.
  4   Initialization error occurred. There is not
      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)

批次示例:

Rem Attempt file copy...
xcopy /D /V %1 %2

Rem Check result code and if it was successful (0), delete the source.
if errorlevel 0 (
    echo Copy completed successfully
    del /Q %1
    exit /B
)

Rem Not Errorlevel 0...
echo Copy failed for some reason.
Run Code Online (Sandbox Code Playgroud)