0

I have a for loop that I'm trying to count each loop however this loop echo's zeros. How do I get it to increment?

@echo off
setlocal enableextensions

set /a count = 0

for /f "Delims=" %%a in (content\docs.html) do (
    set /a count+=1
    echo %count%
)
zachdyer
  • 611
  • 1
  • 9
  • 17
  • 1
    Have a look a this post: http://stackoverflow.com/questions/7522740/counting-in-a-for-loop-using-dos-batch-script. The problem is that `%count%` is evaluated before execution so it will always be zero, see the other post for a solution for this. – Alex May 23 '15 at 16:01
  • [here](http://stackoverflow.com/a/30284028/2152082) is a short but impressive demonstration. – Stephan May 23 '15 at 16:40

1 Answers1

0
@echo off
setlocal enabledelayedexpansion

set /a count = 0

for /f "Delims=" %%a in (content\docs.html) do (
    set /a count+=1
    echo !count!
)

notice the ! instead of %. that's the consequence of using setlocal enabledelayedexpansion.

Jahwi
  • 426
  • 3
  • 14