string path = "C:\dir1\dir2\foo.txt";
string str = "GetFullPath:" + Path.GetFullPath(path) + "
";
str += "GetDirectoryName:" + Path.GetDirectoryName(path) + "
";
str += "GetFileName:" + Path.GetFileName(path) + "
";
str += "GetFileNameWithoutExtension:" + Path.GetFileNameWithoutExtension(path) + "
";
str += "GetExtension:" + Path.GetExtension(path) + "
";
str += "GetPathRoot:" + Path.GetPathRoot(path) + "
";
MessageBox.Show(str);
结果:
GetFullPath:C:dir1dir2foo.txt
GetDirectoryName:C:dir1dir2
GetFileName:foo.txt
GetFileNameWithoutExtension:foo
GetExtension:.txt
GetPathRoot:C: