Sea*_*tar 3 windows batch-file
例如,在批处理文件中,我输入以下命令:
xcopy C:\ fileA.txt D:\ Dir\/ y/d
如果没有名为fileA.txt的文件,它将绝对失败.但我想知道它是否失败,然后向用户输出一些消息.我怎样才能做到这一点?
任何帮助将不胜感激,谢谢!
shi*_*jin 11
大多数命令/程序在成功时返回0,并返回一些其他值,称为errorlevel,以表示错误.
您可以批量检查,例如
if not errorlevel 0 goto ERR
Run Code Online (Sandbox Code Playgroud)
xcopy错误级别:
0 - 复制所有文件时没有错误
1 - 未找到要复制的文件(无效源)
2 - 在复制完成之前,Ctrl-C终止了XCOPY
4 - 发生初始化错误.
5 - 发生磁盘写入错误.
[1] http://m.computing.net/answers/dos/xcopy-errorlevels/7510.html