The rmdir command (OS Windows) gives on completion status values:

Possible exit status values are: 0 - Successful completion. 1 - Failure because directory is not a directory, or because it still contains files or subdirectories. 2 - Failure because of an invalid command line option, or no directory names specified. 

But how to take \ process? Or am I reading something wrong? Suppose in the implementation for a message to the user about the error, and in the positive case for the message about the correct completion of the operation?
For example, with ErrorLevel everything is more or less clear: if ErrorLevel 1 goto Error
What about rmdir? How to, say, redirect on error?

  • And what the command pipeline does not suit: delete and exit, otherwise react to an error: rmdir 11111 && exit & @echo error - Daemon-5

3 answers 3

 rd %foldername% 2>&1 | find "." > nul 

The result is suitable for checking on errorlevel.

    Exit code is the same as error level . The same thing, just named in different places in different ways. Exit code is the WinAPI term - an integer that the program returns with a return or by calling exit (a console program), or as an argument to the ExitProcess function (a window program).

    The same number returned by the program, the Windows shell calls the error level . The general agreement is that 0 signals a successful completion of a program, and a non-zero value signals an error. The program can return different non-zero codes for different errors, but most do not bother and simply return a unit for any error.

    Since the error code can be not one, but generally arbitrary, it will be safer to compare ErrorLevel not with one, but with zero. Unless, of course, you are interested in a particular error code.

      Since rmdir does not change ERRORLEVEL , you can use the OR ( || ) operation. This will not get an error code, but you can check 0 or not 0.

       rmdir testdir || goto :error 

      Similar question in English SO: https://stackoverflow.com/questions/11137702/rd-exits-with-errorlevel-set-to-0-on-error-when-deletion-fails-etc/11137825

      • errorlevel is generally equal to exit status and this is not a variable% errorlevel% - Pavel Gridin
      • Hmm .. I do not know why a minus, but my implementation turned out: rmdir "%AppData%\1C\1Cv82" /S /Q || goto Error_1 goto Normal_1 ... rmdir "%AppData%\1C\1Cv82" /S /Q || goto Error_1 goto Normal_1 ... [/ code] - I_CaR