当前位置: 移动技术网 > IT编程>开发语言>c# > C#中Path类的常用方法

C#中Path类的常用方法

2019年09月06日  | 移动技术网IT编程  | 我要评论

场景

打开vs,输入path,我们可以看到其定义。

 

 

都是静态方法,所以我们可以使用类名直接调用。

实现

新建命令行程序,编码如下:

string str = @"c:\users\administrator\desktop\badao.txt";
            //获得文件名
            console.writeline(path.getfilename(str));
            //获得不包含扩展名的文件名
            console.writeline(path.getfilenamewithoutextension(str));
            //获得文件所在文件夹的名称
            console.writeline(path.getdirectoryname(str));
            //获得文件所在的全路径
            console.writeline(path.getfullpath(str));
            //拼接路径字符串
            console.writeline(path.combine(@"d:\a\b\","c.txt"));
            console.readkey();

 

效果

 

 

关注公众号
霸道的程序猿
获取编程相关电子书、教程推送与免费下载。

大量编程视频教程:

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网