I am trying to use !errorlevel! as a condition inside a loop. I pass error level in a call and then I try and use findstr again to set errorlevel but the condition is not seeing the change.
setlocal EnableDelayedExpansion
for /F %%i in (%Newzips.lst%) do (
echo unzipping %%i >> test.log
wzunzip -o %%i
call :startloop
)
exit /B
:startloop
dir /b *.dat > %Stagedat.lst%
for /F %%l in (%Stagedat.lst%) do (
dir /b E:\NOMADD_FILES\AV\*.dat > %AVdat.lst%
findstr /i /c %%l %AVdat.lst%
echo top error level - !errorlevel!
call :checkdup %%l !errorlevel!
)
exit /B
:checkdup
if !errorlevel! == 0 (
dir /b E:\NOMADD_FILES\AV\*.dat > %AVdat.lst%
findstr /i %1 %AVdat.lst% >> test.log
echo found match so sleep e >> test.log
echo error level - !errorlevel! >> test.log
sleep 3
echo duplicate in AVdat.lst >> test.log
call :checkdup %1 !errorlevel!
)
if !errorlevel! == 1 (
echo copying file %2 >> test.log
move /Y %1 E:\NOMADD_FILES\AV
sleep 5
dir /b E:\NOMADD_FILES\AV\*.dat > %AVdat.lst%
echo moveing AVdat.lst >> test.log
echo error level - !errorlevel! >> test.log
type %AVdat.lst% >> test.log
)
exit /B
:end
So what is happening is after I get down to :checkdup and findstr runs again, !errorlevel! is being updated to 1 but it is still staying inside the top if statement.
This is a sample from the log.
top error level - 0
bcs3_ammo_inv_updates.dat
found match so sleep e
error level - 0
duplicate in AVdat.lst
bcs3_ammo_inv_updates.dat
found match so sleep e
error level - 0
duplicate in AVdat.lst
bcs3_ammo_inv_updates.dat
found match so sleep e
error level - 0
duplicate in AVdat.lst
found match so sleep e
error level - 1
duplicate in AVdat.lst
found match so sleep e
error level - 1
duplicate in AVdat.lst
found match so sleep e
error level - 1
So error level is being set to 1 but it is stuck in the if !errorlevel! == 0 condition. It should go to the other check and continue through the for loop. I've been stuck on this for a couple days now trying many different combinations to get it to work.
Thanks
:checkdup
if !errorlevel! == 0 (
...
echo error level - !errorlevel! >> test.log
sleep 3
rem AND AFTER SLEEP, which is the value of errorlevel?
call :checkdup %1 !errorlevel!
)