title: Cmd : not evaluating variables inside a loop
body: <p>trying to make a .bat script, and need to get some strings working properly.</p>
  
  <p>This is what I've got so far</p>
  
  <pre><code>@echo off
  for /r %%i in (*.csv) do (
  set str=%%i
  set str=%str:csv=rar%
  echo %%i
  echo.%str%
  )
  </code></pre>
  
  <p>Say I've got this running in C:\, and got 5 csv, 1.csv, 2.csv... 5.csv</p>
  
  <p>First time I run it, I get output of:</p>
  
  <pre><code>C:\1.csv
  
  C:\2.csv
  
  C:\3.csv
  
  C:\4.csv
  
  C:\5.csv
  </code></pre>
  
  <p>The second time I get:</p>
  
  <pre><code>C:\1.csv
  csv=rar
  C:\2.csv
  csv=rar
  C:\3.csv
  csv=rar
  C:\4.csv
  csv=rar
  C:\5.csv
  </code></pre>
  
  <p>Then all subsequent calls I get:</p>
  
  <pre><code>C:\1.csv
  rar=rar
  C:\2.csv
  rar=rar
  C:\3.csv
  rar=rar
  C:\4.csv
  rar=rar
  C:\5.csv
  </code></pre>
  
  <p>When what I would be expecting to get is straight through:</p>
  
  <pre><code>C:\1.csv
  C:\1.rar
  C:\2.csv
  C:\2.rar
  C:\3.csv
  C:\3.rar
  C:\4.csv
  C:\4.rar
  C:\5.csv
  C:\5.rar
  </code></pre>
  
  <p>So I remove the substitution:</p>
  
  <pre><code>@echo off
  for /r %%i in (*.csv) do (
  echo %%i
  set str=%%i
  echo.%str%
  )
  </code></pre>
  
  <p>First run:</p>
  
  <pre><code>C:\1.csv
  
  C:\2.csv
  
  C:\3.csv
  
  C:\4.csv
  
  C:\5.csv
  </code></pre>
  
  <p>Second Run:</p>
  
  <pre><code>C:\1.csv
  C:\5.csv
  C:\2.csv
  C:\5.csv
  C:\3.csv
  C:\5.csv
  C:\4.csv
  C:\5.csv
  C:\5.csv
  C:\5.csv
  </code></pre>
  
  <p>It's like it's not set the str variable until the last run of the loop, even though it's trying to echo out the variable, the line of which occurs after the setting, and then saved this for the next loop? Is there something I'm missing on the way it processess loops?</p>
  
  <p>Thanks</p>