Batch file errorlevel reporting incorrect?

  powerless 18:26 14 May 06
Locked

I have this in a batch file..

rmdir /q /s "K:\Application Settings\Opera Settings\profile\"
IF ERRORLEVEL 1 ECHO An error occurred whilst deleting...

However when the 'Profile' directory gets deleted, the IF ERRORLEVEL 1 seems to be called. But it shouldn't should, because the directory gets deleted...If it didn't delete then the ERRORLEVEL 1 should be called.

Shouldn't it?

  DieSse 18:33 14 May 06

It's being called because it's the next command, and will thus automatically be executed.

You need to use a structure such as

rmdir

if error etc goto A

goto end

A: echo an error etc

end: exit

sort of, as best as i recollect have a look here to understand better. click here

  powerless 19:00 14 May 06

It can't be called diesse just because it's there, it's called because the rmdir gave an errorlevel of 1. Of which the IF command springs into action.

  DieSse 07:41 15 May 06

For clarity, it's better to use IF commends with GOTOs, then you can branch to a routine for either condition.

Have you put an @ECHO OFF at the start of your batch file - the default state for ECHO is ON - this would result in all of your commands being shown, including your echo statement.

  powerless 09:53 15 May 06

@ECHO OFF - yes that's there.

  DieSse 12:56 15 May 06

If you want to send me the whole batch file, I'll have a look through it, and try it.

  DieSse 13:07 15 May 06

Or try this -

instead of using IF ERRORLEVEL

use IF EXIST to see if the directory is still there.

  powerless 21:12 15 May 06

Yes...I could use that.

But would still like to know if it is my error in that the errorlevel is wrong...or right...

Batch file emailed...

  powerless 12:26 18 May 06

With the help if DieSse it turns out that RMDIR doesn't support errorlevels.....we think.

So you can use the del command along with: if exist. You could also use it with rmdir as well.

This thread is now locked and can not be replied to.

Surface Pro 5 News - release date, UK price, features, specs

Microsoft Surface Studio hands-on review: the iMac killer is here

Best Mac antivirus 2017