This tip was printed from the MalekTips Computer and Technology Help and Tips website at http://malektips.com.

Windows 2000 and DOS - Execute One Command if Another Fails

SUMMARY: Create error-checking Windows 2000 batch files with this IF-THEN-like construct.

By placing the characters || between two DOS commands using Windows 2000, you can have the second command execute only if the first one fails.

For example, the following command tries to copy file.tmp to file.bk. If file.tmp does not exist or cannot be copied due to a disk failure, an error will be displayed.

copy file.tmp file.bk || echo The File Could Not Be Copied.


 


Press the "print" button on your browser or select "File" - "Print" to print this tip. Then, return to Windows 2000 and DOS - Execute One Command if Another Fails
 
Standard disclaimer applies - read http://malektips.com/disclaim.html.