JozefZ's comment helped me:
Use SETLOCAL EnableDelayedExpansion and! errorlevel! instead of% errorlevel% or (better), return to IfLevelLevel 1 syntax. Setting EnabledDelayedExpansion will expand each variable at runtime rather than parsing: parsing, the command interpreter evaluates the line-by_line and / or command_by_command variables, but the entire code block in () parentheses counts as one command. On the other hand, if ErrorLevel 1 should be read as if ErrorLevel is greater than or equal to 1, which is not equal to 0
source share