0

I am disappointed to see

S:\!DJ DAP>del nofile || pause
Could Not Find S:\!DJ DAP\nofile
S:\!DJ DAP>

i.e. no pause. Cause is revealed by:

S:\!DJ DAP>echo Exit Code is %errorlevel%
Exit Code is 0

What's the most direct workaround?

PS Though official DEL docs don't say errorlevel should be set upon error, this

S:\!DJ DAP>del
The syntax of the command is incorrect.

S:\!DJ DAP>echo Exit Code is %errorlevel%
Exit Code is 1

and this https://ss64.com/nt/del.html suggest it should. By no stretch is missing target file not an error!

ChrisJJ
  • 2,191
  • 1
  • 25
  • 38
  • thegards offers the correct answer. You could work around `del`'s behavior by testing the file exists before attempting to delete it. – J_H Aug 07 '17 at 22:31
  • To play Devil's advocate: why _should_ `del` return an error if the file you asked it to delete isn't there? You have requested a state where the file does not exist. If that state _already exists_, it just means `del` has less work to do to achieve your desired state. – TripeHound Aug 08 '17 at 08:51
  • "You have requested a state where the file does not exist" Incorrect. As the docs says, I have requested to delete a given file. If that operation fails due to the file being absent e.g. due to incorrect name, then that's an error, and I expect the command to return an error code. – ChrisJJ Aug 08 '17 at 10:47

0 Answers0