title: Powershell Get Parent Folder of a File
body: <p>I'm writing a script which archives files for analysis.  My issue is that the file names aren't unique over multiple folders so they are being over written.</p>
  
  <p>For instance:</p>
  
  <pre><code>C:\StuffToCopy\Folder1\myFile1.txt
  C:\StuffToCopy\Folder1\myFile2.txt
  C:\StuffToCopy\Folder2\myFile1.txt
  C:\StuffToCopy\Folder2\myFile2.txt
  </code></pre>
  
  <p>At the end of my copy process I'm only getting 2 files, but I want 4.</p>
  
  <p>I'd like the output to be like this:</p>
  
  <pre><code>C:\ArchiveCopy\Folder1_myFile1.txt
  C:\ArchiveCopy\Folder1_myFile2.txt
  C:\ArchiveCopy\Folder2_myFile1.txt
  C:\ArchiveCopy\Folder2_myFile2.txt
  </code></pre>
  
  <p>Here's my script so far.</p>
  
  <pre><code>$files = dir -r -path "C:\StuffToCopy\" -i *.*
  
  foreach ($file in $files)
  {
      if ($file.LastWriteTime -gt (get-date).AddDays(-1)) {
          copy -path $file C:\ArchiveCopy\
      }
  }
  </code></pre>
  
  <p>I want to do something like <code>copy -path $file.FolderName &amp; '_' &amp; $file C:\ArchiveCopy\</code></p>
  
  <p>I'm just not sure how to do it.</p>