title: Windows batch file - Variables in nested FOR loops
body: <p>I've a list of users in a text file (users.txt) and I want, for each user, to copy every file in their directory (c:\Folder\<em>username</em>) and subdirectory in another directory without subdirectory (c:\Folder 2\<em>username</em>).</p>
  
  <p>I'm now using a batch file containing something like this:</p>
  
  <pre><code>for /f %%u in (user.txt) do (
      for /r "C:\Folder\%%u" %%f in (*.*) do @xcopy "%%f" "C:\Folder 2\%%u" 
  )
  </code></pre>
  
  <p>...but is not working.</p>
  
  <p>After some tests I was able to find out what's wrong: the first %%u variable in the second FOR </p>
  
  <pre><code>for /r "C:\Folder\%%u" %%f in (*.*) do @xcopy "%%f" "C:\Folder 2\%%u"
  </code></pre>
  
  <p>is not correctly replaced by the <em>username</em>.<br>
  Instead the second %%u (inside the DO command) is correctly replaced by it's value.  </p>
  
  <p>Is there a way to force the first %%u variable to take the correct value?</p>