Missing operand in batch file loop

2.1k views Asked by At

I was pretty certain that this should work, but I can't see what the issue is that's causing the missing operand. The loop seems to be working fine, but for some reason the _num variable isn't incrementing as it should. It seems that set /a isn't working as expected here.

@echo off

cls
cd \
cd /d D:\
set /a _num1=1
set /a _num=1
:LOOP 
if exist D:\%_num%.zip (
    set /a "%_num%+=%_num1%"
    goto LOOP
)

echo "%_num%.zip"
pause
exit
@echo on
1

There are 1 answers

2
Endoro On BEST ANSWER
if exist "D:\%_num%.zip" (
    set /a _num+=1
    goto LOOP
)