First problem:
set startnum="!startnum!"+1
Evidently, you wish to add 1
to startnum
.
Your set
command would set startnum
to "!startnum!"+1
. Literally. To perform arithmetic, you need set /a
.
set /A startnum="!startnum!"+1
well, this won't work as "!startnum!
isn't numeric. Had you invoked delayedexpansion
beforehand, then the value of startnum
would have been substituted for !startnum!
yielding set /A startnum="0"+1
which makes more, but still not much sense.
set /A startnum=startnum+1
adds 1 to startnum
- see set /?
from the prompt for documentation.
set /A startnum+=1
would also add 1 to startnum
.
Next problem.
if "%startnum%"="%0%" goto fail
Well, you appear to have found lss
and all that gang. Problem is that the simple comparison operator is ==
, not =
.
if "%startnum%"=="%0%" goto fail
Now - what will that do? It will compare "thecontentsofstartnum" to "thecontentsof0". Since both of these arguments are quoted, batch will perform a string comparison. With a string comparison, 123 is less than 89 because 1
is less than 8
.
But - you are attempting an equivalence comparison (equ
as the operator may be used instead of ==
) so the preceding point is simply AAMOI.
The difficulty is %0%
which you may believe attempts to extract the value of the variable 0
but actually it replaces %0
with the value of the 0th
parameter to the batchfile, which is the batchfile name itself, so you get "batchfilename%" - probably not what you actually wanted.
if "%startnum%"=="0" goto fail
is the way to implement that test.