title: Parse directory name from a full filepath in C#
body: <p>If I have a string variable that has:</p>
  
  <pre><code>"C:\temp\temp2\foo\bar.txt"
  </code></pre>
  
  <p>and I want to get </p>
  
  <p><strong>"foo"</strong></p>
  
  <p>what is the best way to do this?</p>