title: Copying files while preserving directory structure
body: <p>One of our sites was recently hit by a CryptoLocker infection.  Fortunately we caught it early and only have about 8k files encrypted out of the 200k or so on the file-system.  Our backups were good too, so I can restore the files</p>
  
  <p>I have a list of all ~8k of the encrypted files in roughly the following format, one file per new line:</p>
  
  <pre><code>\\nas001\DATA\IQC\file.xls
  \\nas001\DATA\IQC\file2.xls
  \\nas001\DATA\IQC\folder1\file1.xls
  \\nas001\DATA\IQC\folder3\file1.xls
  </code></pre>
  
  <p>I did an ndmp copy of a snapshot of good data, so the backup I am restoring form is another volume on the nas with the same folder structure after a certain point:</p>
  
  <pre><code>\\nas001\IQC_restore\file.xls
  \\nas001\IQC_restore\file2.xls
  \\nas001\IQC_restore\folder1\file1.xls
  \\nas001\IQC_restore\folder3\file1.xls
  </code></pre>
  
  <p>Is there an easy way with powershell (or really, with batch scripting or robocopy) parse the files with the list of encrypted files and copy only those files from our backup to the original location, overwriting the encrypted files?  On another solution I found the following script:</p>
  
  <pre><code>$a = Get-Content "C:\script\hname.txt" 
  foreach ($i in $a) 
      {$files= get-content "C:\script\src.txt"
      foreach ($file in $files)
      {Copy-Item $file -Destination \\$i\C$\temp -force}
      }
  </code></pre>
  
  <p>Which is almost what I need - the <code>foreach $i in $a</code> statement is redundant because I only have one $i, and it's copying all the files listed in the to a single folder rather than copying them in a way to preserve folder structures.</p>
  
  <p>What's the best way to do this?  Can I pass it two separate files and tell it to link the two line for line, so for each line in file <i>a</i> it copies the file to the path in file <i>b</i>?  Is it easier to pass it one set of files (file <i>a</i>), perform a string replacement, and copy to that location?</p>
  
  <p>Thank you!</p>