title: .NET How to check if path is a file and not a directory?
body: <p>I have a path and I need to determine if it is a directory or file.  </p>
  
  <p>Is this the best way to determine if the path is a file?</p>
  
  <pre><code>string file = @"C:\Test\foo.txt";
  
  bool isFile = !System.IO.Directory.Exists(file) &amp;&amp; 
                           System.IO.File.Exists(file);
  </code></pre>
  
  <p>For a directory I would reverse the logic.</p>
  
  <pre><code>string directory = @"C:\Test";
  
  bool isDirectory = System.IO.Directory.Exists(directory) &amp;&amp; 
                              !System.IO.File.Exists(directory);
  </code></pre>
  
  <p>If both don't exists that then I won't go do either branch.  So assume they both do exists.</p>