1.

Solve : Incrementing a for loop?

Answer»

Is it POSSIBLE to increment a for loop counter?

I am aware of for /l that offers a start and end value with an incremental value, but this option does not allow you to parse through a file. i'm LOOKING to traverse the contents of a file and skip certain lines based on a condition. for example:

for /f %%x in (somefile) do (
if %%x==somevalue (skip ITERATION/advance counter) else (some command)
)

from what i have been able to research the only value i can get from %%x is the contents its gathered from the file iteration, not an actual int i can increment.

thanks in advancedexample

Code: [Select]setlocal enabledelayedexpansion
set /a counter=1
for /f %%x in (somefile) do (
if !counter! EQU somevalue (do something) else (do ANOTHER thing)
set /a counter=!counter!+1
)



Discussion

No Comment Found