title: How do I copy files recursively through a directory tree while appending parent folder names to the new files? Batch or VBScript
body: <p>What I'm trying to do is copy a couple hundred images scattered throughout a directory tree and copy them all to another, single folder. I've found out how to do that with 'for /r %i in (*.jpg) ', but my main issue is that the files are all named using the same conventions. Sample:</p>
  
  <pre><code>    Parent_Folder
          001
              file1.jpg
              file2.jpg
          002
              file1.jpg
              file2.jpg
  </code></pre>
  
  <p>The list continues as such. What I'm aiming to do is create this:</p>
  
  <pre><code>    Dest_Folder
          001_file1.jpg
          001_file2.jpg
          002_file1.jpg
          002_file2.jpg
  </code></pre>
  
  <p>where the file's parent directory's name is added to the front of the files (so as to keep them listed in the same order). Not even individually going through every folder and using the "copy &amp; rename" option will work since that will list all files named "file1.jpg" one after the other, "file2.jpg", and so on.</p>
  
  <p>If there's any way to do this in a batch file, that would be much preferred, but a VBScript wouldn't be a bad choice either.</p>
  
  <p>Thanks for any help!</p>
  
  <p>EDIT</p>
  
  <p>Magoo has given the perfect answer for my issue, but it seems his script only works if the source &amp; destination paths have no spaces in them, despite the double quotes. I tried using this same script on another image collection, but with spaces in the paths, and I'm given an error saying the '[word after the first space in the path] was not expected at this time'. It was simple enough to just rename the folders, perform the copy, the rename them back, but is there a workaround for this?</p>