3

I have a batch file that moves a file. I'm testing it and have got an access denied error which I can fix easily, however I've noticed that the errorlevel for this issue is still 0.

I would expect the value to be higher than that. Any ideas?

move /Y "C:\TestNoPersmissions" "E:\somedestination"
echo %errorlevel%
if errorlevel 1 goto Failure
if errorlevel 0 goto Success

:Failure
eventcreate /t error /id 100 /so TestMove /l application /d "Move product XML failure" 
echo Error!

:Success
echo "Success"
pause
halfer
  • 19,824
  • 17
  • 99
  • 186
Richard Banks
  • 2,946
  • 5
  • 34
  • 71
  • 1
    presumably OT, but your `:Failure` response should not fall through to your `:Success` one. Oh, also: you simply expect the wrong thing from `if errorlevel`, which is a very counterintuitive language 'feature'. – underscore_d Apr 26 '18 at 15:01
  • You need to put `goto :EOF` or `exit /B` before `:Failure` and `:Success`; otherwise execution falls into those routines unintentionally... Do you have your `move` and `echo` commands in a loop or any other parenthesised block of code? – aschipfl Apr 26 '18 at 15:08
  • 2
    @underscore_d, this is not the problem here, because the OP did the `if ErrorLevel` checks in descending order. – aschipfl Apr 26 '18 at 15:12
  • Show the exact output so people know what you mean by "ive noticed that the errorlevel for this issue is still", i.e. whether it *really* is or you just mistakenly infer that it is. – underscore_d Apr 26 '18 at 15:14
  • I'd assume that `If ErrorLevel` is returning the success of the `Echo` command. _Remove the `echo %errorlevel%` line and try it again._ – Compo Apr 26 '18 at 15:27
  • 2
    @Compo, didn't we have a thread going on DosTips about which commands reset the errorlevel? Seems odd that `echo` would be one of them. – Squashman Apr 26 '18 at 15:42
  • removing the echo did not make any difference – Richard Banks Apr 26 '18 at 16:00
  • And the errorlevel is definatley 0. I get an access denied to support the fact that the account does not have pernissions. If i update the code and set the source folder to a path that doesnt exist i get an errorlevel 1. – Richard Banks Apr 26 '18 at 16:04
  • possible dupe of ["rd" exits with errorlevel set to 0 on error when deletion fails, etc](https://stackoverflow.com/questions/11137702/batch-exit-code-for-rd-is-0-on-error-as-well/29562902) – underscore_d Apr 26 '18 at 17:30

0 Answers0