title: PowerShell: Find exact folder name
body: <p>I'm trying to find a way to return the full path to a given folder. The problem is that my code returns more than one folder if there is a similar named folder. e.g. searching for "Program Files", returns "Program Files" and "Programs Files <strong>(x86)</strong>". As I didn't ask for "Program Files <strong>(x86)</strong>, I don't want it to return it. I am using:</p>
  
  <pre><code>$folderName = "Program Files"
  (gci C:\ -Recurse | ?{$_.Name -match [regex]::Escape($folderName)}).FullName
  </code></pre>
  
  <p>I thought of replacing -match with -eq, but it will return $false as it's comparing the whole path.</p>
  
  <p>I have thought of maybe returning all matches, then asking the user to select which one is correct, or creating an array that splits the path down and doing an -eq on each folder name and then joining the path again, but my skills are lacking in the array department and cannot get it to work.</p>
  
  <p>Any help or pointers would be gratefully received.</p>
  
  <p>Thanks</p>
  
  <p>Here's what I have used with thanks to Frode:</p>
  
  <pre><code>$path = gci -Path "$drive\" -Filter $PartialPath -Recurse -ErrorAction SilentlyContinue #| ?{$_.PSPath -match [regex]::Escape($PartialPath)} 
  
  ($path.FullName | gci -Filter $filename -Recurse -ErrorAction SilentlyContinue).FullName
  </code></pre>