title: Why does Path.GetFileName() return the name of the correct folder, but Path.GetDirectoryName() returns it parent folder?
body: <p>I have found that using <code>Path.GetFileName()</code> in the code below works as I intend and gives me the name of the correct folder, but if I use <code>Path.GetDirectoryName()</code> it returns the name of the parent (UserGeneratedContent) folder instead. Why does this occur when both methods are passed the same path as a string? And why does <code>Path.GetFileName()</code> work on directories?</p>
  
  <p>When I use <code>Path.GetFileName()</code> the text of the nodes in the Treeview are those of the folders it finds - this is what I want to happen, but if I use <code>Path.GetDirectoryName()</code> the text is the full path from <em>@"UserGeneratedContent"</em> on down for each node. Why does that happen?</p>
  
  <p>And lastly, can my code be improved?      </p>
  
  <pre><code>private void CheckForBaseFolder()
  {
      if (Directory.Exists(@"UserGeneratedContent"))
      {
          DirectoryInfo info = new DirectoryInfo(@"UserGeneratedContent");
          DirectoryInfo[] subdirs = info.GetDirectories();
  
          if (subdirs.Length != 0)
          {
              string path = Path.Combine(@"UserGeneratedContent", subdirs[0].ToString());
              treeView1.Nodes.Add(CheckForSubFolders(path));
              treeView1.SelectedNode = treeView1.Nodes[0];
          }
          else { MessageBox.Show("No User-Generated Folders Or Files Found"); }    
      }
      else { Directory.CreateDirectory(@"UserGeneratedContent"); }
  }
  
  private TreeNode CheckForSubFolders(string path)
  {
      TreeNode folder = new TreeNode(path);
  
      folder.Text = Path.GetFileName(path); // Works as intended, but.....
      folder.Text = Path.GetDirectoryName(path); // Returns the parent folder 
  
      foreach(var subdirectory in Directory.GetDirectories(path))
      {
          folder.Nodes.Add(CheckForSubFolders(subdirectory));                
      }
  
      folder.ImageIndex = 0;
      folder.SelectedImageIndex = 1;
  
      return folder;
  }
  </code></pre>