1.

Solve : Increment variabile?

Answer»

Hi,

Why in this batch file the count  variabile doesn't increment ?
I want to put each line from a file in SEPARATE file .

Code: [Select]if "%1"=="" goto :ERROR
set count=0


for /f "tokens=* DELIMS= " %%a in (c:\IN\%1) do (
set count=%count%+1
  echo %%a > c:\in\%1_DIR\%count%
)

:ERROR

Thank you,
Bogdan

becouse VARIABLES in for and if COMMANDS ned to be in ! no in % and you must use setlocal at start


Code: [Select]setlocal enabledelayedexpansion
if "%1"=="" goto :ERROR
set count=0


for /f "tokens=* delims= " %%a in (c:\IN\%1) do (
set count=!count!+1
  echo %%a > c:\in\%1_DIR\!count!
)

:ERRORIt's OK now , but it's create file name like that "0+1", "0+1+1", "0+1+1+1" ...   
The variabile count it's interpretate as string.

BogdanBecause you need

set /a count=!count!+1

Yes ... it's working .
Thank everybody .

Bogdan



Discussion

No Comment Found