title: How can I go to parent directories? (C#)
body: <pre><code>if (Console.ReadKey(true).Key == ConsoleKey.E)
  {
      Console.Clear();
      Console.WriteLine(&quot;Enter path: &quot;);
      string Answer = Console.ReadLine();  
       foreach (var SelectedDir in System.IO.Directory.GetDirectories(Answer))
    {
        Console.WriteLine(SelectedDir + &quot;\n&quot;);
    }
      string RootPath = Console.ReadLine();
      Console.Clear();
        Console.WriteLine(&quot;What would you like to do with &quot; + RootPath + &quot;?&quot;);
        Console.WriteLine(&quot;A)Access Folder\nB)Delete Folder (Has to be empty)&quot;);
     if (Console.ReadKey(true).Key == ConsoleKey.A)
     {
       AccessFolder(RootPath);
     }
     else if (Console.ReadKey(true).Key == ConsoleKey.B)
        {
         System.IO.Directory.Delete(RootPath);
  
        } 
           AccessFolder(RootPath); 
  }
  static void AccessFolder(string RootPath)
  {
    foreach (var SelectedRoot in System.IO.Directory.GetDirectories(RootPath))
    {
      Console.WriteLine(SelectedRoot + &quot;\n&quot;);
    } 
    string NextRoot = Console.ReadLine();
    Console.Clear(); 
    Console.WriteLine(&quot;What would you like to do with &quot; + NextRoot + &quot;?&quot;);
    Console.WriteLine(&quot;A) Access Folder\nB)Delete Folder (Has to be empty)&quot;);
    if (Console.ReadKey(true).Key == ConsoleKey.A)
    {
      AccessFolder(NextRoot);
    }
    else if (Console.ReadKey(true).Key == ConsoleKey.B)
    {
      System.IO.Directory.Delete(NextRoot);
  
    }
  } 
  </code></pre>
  <p>I can't figure out how to go to the parent root. I've been trying for 2 days and couldn't come up with anything.
  I thought about passing the directory into a string and whenever the user wants to go to the parent of the directory he's in, the path will be equal to RootPath which will be passed into the AccessFolder method. I'm not sure if this is practical or whether it would cause issues.
  Say if I had the directory &quot;D:\StackOverflow\Test&quot;, is it a good idea to remove all text that is after the last \ so the directory's path would be &quot;D:\StackOverflow&quot;?
  Any help is much appreciated.</p>