class Program { static void sub(string path) { Console.Write($"Path.GetDirectoryName(\"{path}\") => "); var d = Path.GetDirectoryName(path); if (d == null) Console.WriteLine("null"); else if (d.Length == 0) Console.WriteLine("zero length string"); else Console.WriteLine(d); } static void Main() { sub(@"a:\x.txt"); sub(@"a\x.txt"); sub(@"\x.txt"); sub(@"x.txt"); sub(@"a:\"); sub(@"a:"); sub(@"\\.\d