Errorlevel in a For loop (Windows batch)

Add

setlocal EnableDelayedExpansion

to the start of your script, then use
!errorlevel! instead of %errorlevel%

Delayed Expansion will cause variables to be expanded at execution
time rather than at parse time

~ http://ss64.com/nt/delayedexpansion.html

The answer to another question that pointed me in the right direction:
Errorlevel of command executed by batch for loop

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)