title: CMD For Loop does not hold set /a value
body: <p>Didn't know how to explain this well, so here is the code</p>
  
  <pre><code>@echo off
  set test=0
  
  for /f %%a in (textfile.txt) do (
  rem loops five times(5 lines in textfile.txt)
  
  set /a test=test+1
  rem Adds 1 to Test
  
  echo %%a
  rem Echo's correct line in file
  
  echo %test%
  rem Echo's whatever X was before the loop
  
  )
  
  echo %test%
  rem Displays the correct value of X
  
  pause
  </code></pre>
  
  <p>this is just an example of where I am finding the problem, txtfile.txt has 5 lines, so the for loop goes 5 times, each time, test gets +1 to it, and the /a displays the correct value of X, but the last echo on the for loop displays 0, which is what test is set to before the loop.</p>
  
  <p>The value of test is not changing until the loop is finished... is there any way to fix this?</p>
  
  <p>Here is what I want to accomplish, as there may be an easier way: I want to run a for loop that findstr's all rtf's in a series of sub folders, and copies them all to a all directory with a new name, 1.rtf,2.rtf,3.rtf, etc. The reason I need to rename them on the transfer is they all have the same name.</p>