title: Batch file variables initialized in a for loop
body: <p>I have a batch file which initializes variables via SET inside a for loop, for a set of files on disk:</p>
  
  <pre><code>for %%f in (%MYTARGETDIR%\*config.xml) do (
    SET TMPFILE=%%F.tmp
  
    echo In loop %TMPFILE%
  )
  
  echo End loop %TMPFILE%
  </code></pre>
  
  <p>when I run this in a brand new command shell (without TMPFILE defined) the In loop echo is empty, but the end loop echo is not.</p>
  
  <p>When I run a second time, its already set, and outputs its value, ignoring the set until the loop closes.</p>
  
  <p>Ideas why this is, and what the workaround is?</p>