del command errorlevel

Microsoft Windows
Post Reply
User avatar
MigrationUser
Posts: 336
Joined: 2021-Jul-12, 1:37 pm
Contact:

del command errorlevel

Post by MigrationUser »

22 Jan 2009 02:24
zammalabe

maybe i have missed something, but can somebody tell me is there any errorlevel (or similar implementation) for del command in winxp? i assumed, that errorlevel==0 when the command succeeded and when errorlevel==1 the command failed? thats seems to work with copy command, but wit del command :pc: ... huhh sad

yeah, i know the piping errors :|

2>

, but to use that in simple batch file for task such "when deletion files, do something", is little bit :cry: ....

----------------------------

#2 22 Jan 2009 05:15
carlos


The errorlevel 0 is succes.
The errorlevel different of 0 is fail. (-1,1,2,3,4,9009,etc)

Example:

Code: Select all

program [args] && (echo.Success) || (echo.Fail)
or

Example:

Code: Select all

program [args]
if errorlevel 1 (
echo.Fail
) else (
if errorlevel 0 (echo.Success) else (
echo.Fail
)
)
Must be this way because if errorlevel is greater than or equal number.


But as del seems like the always returns 0. I could do:

Code: Select all

del /f /q /a "file.txt" >nul 2>&1
if exist "file.txt" (echo.Fail) else (
echo.Success
)
or

Code: Select all

del /f /q /a "file.txt" >nul 2>&1
dir /a "file.txt" >nul 2>&1 && (echo.Fail) || (echo.Success)
In these last two cases, the logic is reversed.

Last edited by carlos (22 Jan 2009 05:41)

----------------------------

#3 22 Jan 2009 13:50
bluesxman


How about this?

Code: Select all

del /f /q/ a "file.txt" 2>&1 | findstr "." > nul 
if errorlevel 1 (echo:Success) ELSE (echo:Fail)
The theory being that &2 will be empty if the delete was successful.

Last edited by bluesxman (22 Jan 2009 13:50)

cmd | *sh | ruby | chef
Post Reply