Batch file errorlevel reporting incorrect?

  powerless 18:26 14 May 2006

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 2006

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

You need to use a structure such as


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 2006

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 2006

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 2006

@ECHO OFF - yes that's there.

  DieSse 12:56 15 May 2006

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 2006

Or try this -

instead of using IF ERRORLEVEL

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

  powerless 21:12 15 May 2006

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 2006

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.

Elsewhere on IDG sites

HTC U12 Plus review: Hands-on

See how VFX studio Rise created 'Jabariland', holograms & digital doubles in Marvel Studios' Black…

Best Android emulators for Mac

Comment importer des contacts d’un iPhone à un autre iPhone ?