"Offering free computer help, hints, and tips to the Internet populace." Now with over 3,820 tips!

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.



 

Got something to add? Post a comment!

Everyone is invited to submit comments. Registered users also receive their own visitor profile page with a summary of recent posts.
Register | Login

Your name:
 E-mail:
* Home/Blog Page:
Comment:
(Max chars: 5000)

* = optional field

 


Print This Tip

Get E-Mail When New Tips are Online

Return to the Windows 2000 and DOS page.

 


New in MalekTips:

RSS Feeds- Subscribe!

You want the latest tech tips and tricks in your e-mail Inbox - FREE? Type your e-mail address below and click 'Get Tips!'.
 


( sample / details )
( opt-out instructions )