首页 > 其他 > 详细

C# 获取路径中文件名、目录、扩展名等

时间:2014-03-26 11:16:46      阅读:499      评论:0      收藏:0      [点我收藏+]
bubuko.com,布布扣
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:\
bubuko.com,布布扣

C# 获取路径中文件名、目录、扩展名等,布布扣,bubuko.com

C# 获取路径中文件名、目录、扩展名等

原文:http://www.cnblogs.com/vip-ygh/p/3620808.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!