public static void Main()
Console.WriteLine("Test001 "+ pathCombine("/foo/bar.baz"));
Console.WriteLine("Test002 "+ pathCombine("//foo/bar.baz"));
Console.WriteLine("Test003 "+ pathCombine("\\foo/bar.baz"));
Console.WriteLine("Test004 "+ pathCombine("foo/bar", "baz.bag"));
Console.WriteLine("Test005 "+ pathCombine("foo\\bar", "baz.bag"));
Console.WriteLine("Test101 "+ Path.GetFileName("/foo/bar.baz"));
Console.WriteLine("Test102 "+ Path.GetFileName("bar.baz"));
Console.WriteLine("Test103 "+ Path.GetFileName(""));
Console.WriteLine("Test104 "+ Path.GetFileName("\\foo\\bar.baz"));
Console.WriteLine("Test105 "+ Path.GetFileName(@"\\server\share\foo.bar"));
string doubleEscapedPath = "\\\\server\\share\\foo.bar";
Console.WriteLine("Test106 "+ Path.GetFileName(doubleEscapedPath));
Console.WriteLine("Test200 "+ pathUsingSubstring("foo\\bar.baz"));
Console.WriteLine("Test201 "+ Path.GetDirectoryName("/foo/bar.baz"));
Console.WriteLine("Test202 "+ Path.GetDirectoryName("foo/bar.baz"));
public static string pathCombine(params string[] paths)
return Path.Combine(paths).Replace('\\', '/');
public static string pathUsingSubstring(string path)
int index = path.LastIndexOf("\\");
return path.Substring(0, index);