string path = "C://dir1//dir2//foo.txt";
string str = "GetFullPath:" + Path.GetFullPath(path) + "/r/n";
str += "GetDirectoryName:" + Path.GetDirectoryName(path) + "/r/n";
str += "GetFileName:" + Path.GetFileName(path) + "/r/n";
str += "GetFileNameWithoutExtension:" + Path.GetFileNameWithoutExtension(path) + "/r/n";
str += "GetExtension:" + Path.GetExtension(path) + "/r/n";
str += "GetPathRoot:" + Path.GetPathRoot(path) + "/r/n";
MessageBox.Show(str);
GetFullPath:C:/dir1/dir2/foo.txt
GetDirectoryName:C:/dir1/dir2
GetFileName:foo.txt
GetFileNameWithoutExtension:foo
GetExtension:.txt
GetPathRoot:C:/
本文通过一个具体的示例,展示了如何使用C#中的Path类来获取文件的各种路径信息,包括完整路径、目录名称、文件名、不含扩展名的文件名、文件扩展名以及路径根。
453

被折叠的 条评论
为什么被折叠?



