Batch File - REN command's ErrorLevel returns 0 even on failure

Posted by FMFF on Stack Overflow See other posts from Stack Overflow or by FMFF
Published on 2010-04-07T14:11:52Z Indexed on 2010/04/07 14:43 UTC
Read the original article Hit count: 445

Filed under:
|
|

This is related to my earlier question.

ren "C:\Temp\%%A" "C:\Temp\%%A"
if errorlevel 0 (
          "C:\Program Files\7-Zip\cmdline\7za.exe" a -tzip -mx9 "C:\temp\Zip\%%A.zip" "C:\temp\%%A"
           Move "C:\temp\%%A" "C:\Temp\Archive"
                )

In the above, the IF evaluates to true always, even if REN command fails.

The idea is to check if a file is not locked by any other application, if not then Archive it and move it elsewhere.

How best to do this?

Thank you.

© Stack Overflow or respective owner

Related posts about rename

Related posts about batch-file