For example, in a batch file, I typed the command below:
xcopy C:\fileA.txt D:\Dir\ /y /d
It will fail absolutely if there was not a file called fileA.txt. But I want to know if it fails, then output some messages to user. How can I do this?
Any help will be grateful, thanks!
Most commands/programs return a 0 on success and some other value, called errorlevel, to signal an error.
You can check for this in you batch for example by
xcopy errorlevels:
0 – All files were copied without errors
1 – No files were found to copy (invalid source)
2 – XCOPY was terminated by Ctrl-C before copying was complete
4 – An initialization error occurred.
5 – A disk-write error occurred.
[1] http://m.computing.net/answers/dos/xcopy-errorlevels/7510.html