title: C# Best way to get folder depth for a given path?
body: <p>I'm working on something that requires traversing through the file system and for any given path, I need to know how 'deep' I am in the folder structure. Here's what I'm currently using:</p>
  
  <pre><code>int folderDepth = 0;
  string tmpPath = startPath;
  
  while (Directory.GetParent(tmpPath) != null) 
  {
      folderDepth++;
      tmpPath = Directory.GetParent(tmpPath).FullName;
  }
  return folderDepth;
  </code></pre>
  
  <p>This works but I suspect there's a better/faster way? Much obliged for any feedback.</p>