System.IO.Path相关常用函数使用介绍

本章讲述:System.IO.Path相关常用函数使用介绍

1、GetFileName(string path):返回指定路径字符串的文件名和扩展名

string localDir = System.IO.Path.GetFileName(@"D:\360Downloads\Software\filelist.dat");

返回结果为:filelist.dat

2、GetFileNameWithoutExtension:返回不具有扩展名的指定路径字符串的文件名;
返回System.IO.Path.GetFileName(System.String) 的字符串,但不包括最后的句点 (.) 以及之后的所有字符;

string appCode = System.IO.Path.GetFileNameWithoutExtension(@"D:\360Downloads\Software\filelist.dat");

返回结果:filelist

3、Combine:将字符串或者字符串数组,组合成一个路径;注意字符串中是否含无效字符,会异常

Combine(string path1, string path2, string path3);
Combine(string path1, string path2);
Combine(string path1, string path2, string path3, string path4);
Combine(params string[] paths);

4、GetDirectoryName(string path):返回指定路径字符串的目录信息;path:文件或目录的路径

string localDir = System.IO.Path.GetDirectoryName(@"D:\360Downloads\Software\filelist.dat");

返回结果为:Software

5、GetExtension(string path):返回指定的路径字符串的扩展名

string localDir = System.IO.Path.GetExtension(@"D:\360Downloads\Software\filelist.dat");

返回结果为:dat

6、GetFullPath(string path):返回指定路径字符串的绝对路径

7、GetPathRoot(string path):获取指定路径的根目录信息;此方法不会验证路径是否存在

string localDir = System.IO.Path.GetPathRoot(@"D:\360Downloads\Software\filelist.dat");

返回结果为:D:\

string localDir = System.IO.Path.GetPathRoot(@"\Software\");

返回结果为:\

string localDir = System.IO.Path.GetPathRoot(@"filelist.dat");

返回结果为:""

8、HasExtension(string path):确定路径是否包括文件扩展名

9、HasExtension(string path):获取指示指定的路径字符串是否包含根的值

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值