码迷,mamicode.com
首页 > Windows程序 > 详细

【.Net】C# 根据绝对路径获取 带后缀文件名、后缀名、文件名、不带文件名的文件路径

时间:2017-07-12 15:29:35      阅读:297      评论:0      收藏:0      [点我收藏+]

标签:default   .net   c#   physical   without   log   rect   length   char   

1、c#根据绝对路径获取 带后缀文件名、后缀名、文件名。

 

 
1                 string str =" F:\test\Default.aspx";
2                 string filename = System.IO.Path.GetFileName(str);//文件名 “Default.aspx”
3                 string extension = System.IO.Path.GetExtension(str);//扩展名 “.aspx”
4                 string fileNameWithoutExtension = System.IO.Path.GetFileNameWithoutExtension(str);// 没有扩展名的文件名 “Default”
5 
6                 string directory=System.IO.Path.GetDirectoryName(physicalPath);
 

2、c#根据绝对路径获取 带后缀文件名、后缀名、文件名,使用 Split 函数。

1                 string str = =" F:\test\Default.aspx";
2                 char[] delimiterChars = { ‘.‘, ‘\\‘ };
3                 string[] Mystr = str.Split(delimiterChars);
4                 string sheetName = Mystr[Mystr.Length - 2];);// 没有扩展名的文件名 “Default”
 

【.Net】C# 根据绝对路径获取 带后缀文件名、后缀名、文件名、不带文件名的文件路径

标签:default   .net   c#   physical   without   log   rect   length   char   

原文地址:http://www.cnblogs.com/yanglang/p/7154886.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!