1

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
rick-pri
  • 73
  • 8

1 Answers1

2
if exist "D:\%_num%.zip" (
    set /a _num+=1
    goto LOOP
)
Endoro
  • 37,015
  • 8
  • 50
  • 63
  • +1, The minimum change required to get OP's code to work is `set /a "_num+=%_num1%"`. I would probably use `set /a "_num+=_num1"` – dbenham Aug 28 '13 at 04:35
  • Endoro, exactly what I was trying to achieve and reducing the amount of code I had. I don't know how many times that I have to relearn this lesson with variables in CMD for it to stick. dbenham, you're right, however, I liked Endoro's thinking. – rick-pri Aug 28 '13 at 07:37