Search code examples
c#console

C# '..' directory exists somehow


So I'm currently working on a Console application and I have a navigation system with the 'cd' command to move up. To make sure you haven't entered a path I check for the directory with Directory.Exists(".."), but this returns true in some way. Even if I enter that in the Immediate window in Visual Studio it returns true, and I'm not sure what is causing that.
Any help is welcome!

A code example:

    string path = "..";
    if (Directory.Exists(path))
        // Some code that shouldn't run but does
    else
        // Some more code that should run but doesn't
``

Solution

  • As you can read in the comments, '..' means the parent directory, so it of course Directory.Exists("..") returns true. I didn't know this was a thing in C#, but this saves me some code and time! Again, thanks everybody for the help!