Computing.Net > Forums > Programming > Help with error levels

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Help with error levels

Reply to Message Icon

Name: amlife
Date: October 22, 2008 at 06:40:17 Pacific
OS: OS XP
CPU/Ram: 2GB
Product: DELL
Comment:

Hello guys
I just want to know if what I'm doing works!
I have bunch of code gets executed line by line.

ex.
IF EXIST C:\filename.txt DEL C:\filename.txt
if errorlevel 1 echo File has been deleted.

however if I have tens of lines. will I need to specify error levels for each line. error level 1 for one and error level 2 for second line .. etc ???



Sponsored Link
Ads by Google

Response Number 1
Name: IVO
Date: October 22, 2008 at 07:26:36 Pacific
Reply:

Under Windows NT/2K/XP you can code

if %ErrorLevel% equ # <your command>

type if /? to know about other relational operators (e.g. gtr, lss and so on)


0

Response Number 2
Name: IVO
Date: October 22, 2008 at 07:35:14 Pacific
Reply:

Sorry,

I did not understand your question, so now I hope to give you the right response.

The ErrorLevel is not bound to the line position, it is set by the latest command executed. So if you want to check for a failed action you have to code always

if ErrorLevel 1

no matter how many times. Keep in mind if ErrorLevel is satisfied for return codes equal or greater than the value indicated.


0

Response Number 3
Name: Mechanix2Go
Date: October 22, 2008 at 09:06:30 Pacific
Reply:

"IF EXIST C:\filename.txt DEL C:\filename.txt"

will return 0 regardless


=====================================
If at first you don't succeed, you're about average.

M2


0

Response Number 4
Name: amlife
Date: October 22, 2008 at 17:10:11 Pacific
Reply:

Thanks alot for your help :-D


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More


Compare two files for unm... Help needed in Batch scri...



Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Help with error levels

Error level in batch file www.computing.net/answers/programming/error-level-in-batch-file/16461.html

Help with C++ and Mod 11 program www.computing.net/answers/programming/help-with-c-and-mod-11-program/5553.html

Help with a C Program / Newbie www.computing.net/answers/programming/help-with-a-c-program-newbie/8071.html