当前位置: 移动技术网 > IT编程>开发语言>c# > c# Path路径类

c# Path路径类

2020年04月25日  | 移动技术网IT编程  | 我要评论
c Path路径类 Path类是static类型 常用方法 实现 属性方法 | 属性或方法 | 作用 | | | | | string ChangeExtension(string path, string extension) | 更改路径字符串的扩展名 | | string Combine(pa ...

c# path路径类

path类是static类型

常用方法

path.getfullpath(file) 取全路径
path.getfilename(file) 取文件名,包含扩展名
path.getfilenamewithoutextension(file) 取文件名,不包含扩展名
path.getextension(file) 取扩展名
path.getdirectoryname(file) 取路径名
path.getpathroot(file)  取盘符
path.combine(file1,file2) 合并2个路径

实现

string str = @"c:\users\administrator\desktop\ceshi.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();

属性方法

属性或方法 作用
string changeextension(string path, string extension) 更改路径字符串的扩展名
string combine(params string[] paths) 将字符串数组组合成一个路径
string combine(string path1, string path2) 将两个字符串组合成一个路径
string getdirectoryname(string path) 返回指定路径字符串的目录信息
string getextension(string path) 返回指定路径字符串的扩展名
string getfilename(string path) 返回指定路径字符串的文件名和扩展名
string getfilenamewithoutextension(string path) 返回不具有扩展名的指定路径字符串的文件名
string getfullpath(string path) 返回指定路径字符串的绝对路径
char[] getinvalidfilenamechars() 获取包含不允许在文件名中使用的字符的数组
char[] getinvalidpathchars() 获取包含不允许在路径名中使用的字符的数组
string getpathroot(string path) 获取指定路径的根目录信息
string getrandomfilename() 返回随机文件夹名或文件名
string gettemppath() 返回当前用户的临时文件夹的路径
bool hasextension(string path) 返回路径是否包含文件的扩展名
bool ispathrooted(string path) 返回路径字符串是否包含根

如您对本文有疑问或者有任何想说的,请 点击进行留言回复,万千网友为您解惑!

相关文章:

验证码:
移动技术网