Article ID: 39585 - View products that this article applies to.
This article was previously published under Q39585
When you use multiple IF ERRORLEVEL statements in batch files, the order in which the ERRORLEVELs are tested numerically is important. The correct order is descending (highest to lowest). This ordering is from the way ERRORLEVELs are tested. The IF condition is set to TRUE when the ERRORLEVEL is equal to, or greater than, the ERRORLEVEL number.
The following batch file fragment demonstrates this INCORRECT behavior:
The above example always branches to the "ZERO" label, regardless of success or failure. This example would work correctly if the ERRORLEVEL testing was made in descending order.
The CORRECT way to write such a batch file is as follows:
Article ID: 39585 - Last Review: May 12, 2003 - Revision: 2.0
Retired KB Content Disclaimer
This article was written about products for which Microsoft no longer offers support. Therefore, this article is offered "as is" and will no longer be updated.
Contact us for more help