title: Using batch files to copy all files from a directory tree to a single directory
body: <p>I needed to copy all the files from a directory tree into a single directory. A quick search provided me with <a href="https://superuser.com/questions/137336/copy-all-files-in-subfolders-to-single-folder-on-xp">this</a> method:</p>
  
  <pre><code>for /f "tokens=*" %a in ('dir /b /s /a-d') do @copy "%a" "c:\Single-Folder"
  </code></pre>
  
  <p>I tried it, and it worked just fine. Deciding to simplify things a bit, I created a quick batch file so I didn't have to look this up in the future. my batch file looks like this:</p>
  
  <pre><code>set COPY_FROM="C:\Users\me\Desktop\Disc 1"
  set COPY_TO="C:\Testing\test"
  
  cd %COPY_FROM%
  for /f "tokens=*" %a in ('dir /b /s /a-d') do @copy %COPY_TO%
  pause
  </code></pre>
  
  <p>Unfortunately, when I execute this, I get the error: </p>
  
  <pre><code>C:\Users\me\Desktop\Tools&gt;set COPY_FROM="C:\Users\me\Desktop\Disc 1"
  
  C:\Users\me\Desktop\Tools&gt;set COPY_TO="C:\Testing\test"
  "\Users\me\Desktop\Disc 1"') was unexpected at this time.
  C:\Users\me\Desktop\Tools&gt;for /f "tokens=*" "\Users\me\Desktop\Disc 1"') do @copy "\Testing\test"
  </code></pre>
  
  <p>What works if I enter it into the command line does not work when run as a batch file. I did try replacing the variables with the actual path, but got the same error. Even when I create a batch file with only the line that works from the command line, it doesn't work when running from the file. Does anyone know what I am doing wrong?</p>
  
  <p>Thank you in advance for any assistance.</p>