Unable to increment and print inside a Windows Batch for loop [duplicate]

  auto-increment, batch-file, for-loop, windows

I’m new to Windows batch.

I’m trying to read lines from a file input.txt and print run<increment-value> thus for the first line it should print run1 and for the second line run2 and so on.

Below is what I tried:

set /a c=1
@echo off
for /f "tokens=*" %%a in (index.txt) do (
set /a c=c+1
echo incvalue=run%c%
echo line=%%a
)
pause

In the output, I see the line= prints each line which is what I want but the incremental value of the loop always prints run1 i.e does not increment.

Can you please suggest?

Source: StackOverflow

LEAVE A COMMENT