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

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

我想使用xcopyVerify 标志在网络上移动而不是复制文件。我在 xcopy 上找不到移动文件的开关,有没有xmove可以使用的verify

目前我正在使用xcopy /D /V,但需要从源头删除文件仅有的验证后文件已成功复制到目标。

答案1

您应该查看一下robocopy,它比 功能强大得多xcopy。您可以使用/MOV或轻松移动文件/MOVE

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

robocopy from_folder to_folder files_to_copy /MOV

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

robocopy from_folder to_folder files_to_copy /MOVE

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

答案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.

示例批次:

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.

相关内容