0

I'm new in batch and have made a program that writes a file with the %num% variable.
I'm having problems with the sum. Instead of returning 1, 2 and 3, it returns (0+1),((0+1)+1) and (((0+1)+1)+1)...
Here is the code:

set num=0
:loop
set num=(%num%+1)
echo test > "%num%".txt
pause

goto loop;
crockeea
  • 21,651
  • 10
  • 48
  • 101
A. O.
  • 670
  • 1
  • 6
  • 16
  • possible duplicate of [Calculating the sum of two variables in a batch script](http://stackoverflow.com/questions/10674974/calculating-the-sum-of-two-variables-in-a-batch-script). Please search the existing questions before adding one of your own. – Adam Liss Apr 12 '14 at 14:43

2 Answers2

1

you need the /a parameter to do arithmetics:

set /a num=%num%+1

shorter:

set /a num=num+1

even shorter:

set /a num+=1
Stephan
  • 53,940
  • 10
  • 58
  • 91
0

Try it like below

@echo off
set num=0
:loop
set  /a num=%num%+1
echo test > %num%.txt
pause

goto loop;
Rahul
  • 76,197
  • 13
  • 71
  • 125