Batch file question

B

Brother Brock

Hello, All! please find here below my batch file.
(isdate d:\batch\temp.txt NOT EQUAL TODAY
if errorlevel 1 set true_=No
if errorlevel 0 set true_=Yes)

Even when the isdate command returns an errorlevel 1 the variable true_ sets
Yes. Somebody please point out the error in the batch file. Thanks in
advance.

With best regards, Brother Brock. E-mail: (e-mail address removed)
 
D

David Candy

If errorlevel is HIGHER is what the line means.

(isdate d:\batch\temp.txt NOT EQUAL TODAY
if errorlevel 0 set true_=Yes)
if errorlevel 1 set true_=No

will work though true_ will equal yes then no

and also

Test for errorlevel
If errorlevel n if not errorlevel n+1 <command to do>As errorlevel tests always test for a number equal or higher, this code snippet only evaluates if the number is exactly the same. So if testing for errorlevel 6

If errorlevel 6 if not errorlevel 7 Echo The error level was 6
 
R

Ron Martell

Brother Brock said:
Hello, All! please find here below my batch file.
(isdate d:\batch\temp.txt NOT EQUAL TODAY
if errorlevel 1 set true_=No
if errorlevel 0 set true_=Yes)

Even when the isdate command returns an errorlevel 1 the variable true_ sets
Yes. Somebody please point out the error in the batch file. Thanks in
advance.

With best regards, Brother Brock. E-mail: (e-mail address removed)

errorlevel works on an "equal to or greater than" basis so you must
use a goto command to skip past the tests for lower values.


Try this:

if errorlevel 1 goto level1
(the preceding line will be processed if errorlevel is 1 or higher)

set true_=Yes
goto finish
(the above 2 lines will be processed only if errorlevel is less than
1)


:level1
set true_=No

:finish
(balance of batch file commands)

Good luck

Ron Martell Duncan B.C. Canada
--
Microsoft MVP
On-Line Help Computer Service
http://onlinehelp.bc.ca

In memory of a dear friend Alex Nichol MVP
http://aumha.org/alex.htm
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top