Just stumbled into a weird thing with %ERRORLEVEL% and wanted to see if anyone knows why and if there\'s a way to fix it. Essentially, it seems as if commands e
%ERRORLEVEL%
Try using setlocal enabledelayedexpansion at the start of your batch file, and !ERRORLEVEL! inside your IF. This seems to work for me:
setlocal enabledelayedexpansion
!ERRORLEVEL!
IF
@echo off setlocal enabledelayedexpansion dir nul echo %ERRORLEVEL% if .1.==.1. ( urklbkrlksdj - not a command echo %ERRORLEVEL% echo !ERRORLEVEL! )