Bug in Directory.GetParent?

Posted on

Problem :

I was hit in the face by a very weird behavior of the System.IO.Directory.GetParent method:

string path1 = @"C:foobar";
DirectoryInfo parent1 = Directory.GetParent(path1);
Console.WriteLine (parent1.FullName); // Prints C:foo, as expected

// Notice the extra backslash. It should still refer to the same location, right ?
string path2 = @"C:foobar"

Solution :

Leave a Reply

Your email address will not be published. Required fields are marked *