title: Copy file with relative path
body: <p>I would like to copy all files of a certain type from a certain sub-directory with their relative path from that sub-directory to another directory with the relative path intact. e.g.:</p>
  
  <p>Source sub-dir: </p>
  
  <pre><code>c:\temp\sourcedirectory
  </code></pre>
  
  <p>Source files:</p>
  
  <pre><code>c:\temp\sourcedirectory\tonymontana\fileOne.txt
  c:\temp\sourcedirectory\poker\fileTwo.txt
  </code></pre>
  
  <p>Target dir:</p>
  
  <pre><code>c:\temp\targetdirectory
  </code></pre>
  
  <p>Desired result:</p>
  
  <pre><code>c:\temp\targetdirectory\tonymontana\fileOne.txt
  c:\temp\targetdirectory\poker\fileTwo.txt
  </code></pre>
  
  <p>So far I've come up with:</p>
  
  <pre><code>Set-Location $srcRoot
  Get-ChildItem -Path $srcRoot -Filter $filePattern -Recurse |
      Resolve-Path -Relative |
      Copy-Item -Destination {Join-Path $buildroot $_.FullName}
  </code></pre>
  
  <p>However, this "everything is an object" à la PowerShell is beating me down (at least that's what I suspect). I.e. the files gets copied, but without their relative path. </p>
  
  <p>Anyone who could enlighten me a bit?</p>