当前位置:asp编程网>技术教程>Net教程>  正文

C#获取路径中文件名、目录、扩展名等相关信息代码

2017-05-26 14:43:43   来源:csdn   作者:佚名   浏览量:3252   收藏

C#获取路径中文件名、目录、扩展名等相关信息代码

直接上代码

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:\



关于我们-广告合作-联系我们-积分规则-网站地图

Copyright(C)2013-2017版权所属asp编程网