我想使用xcopy
Verify 标志在网络上移动而不是复制文件。我在 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
答案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.