C# 根据绝对路径获取 带后缀文件名、后缀名、文件名、不带文件名的文件路径
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”
名称 | 说明 | |
---|---|---|
![]() ![]() ![]() |
ChangeExtension | 更改路径字符串的扩展名。 |
![]() ![]() |
Combine( String[] ) | 将字符串数组组合成一个路径。 |
![]() ![]() ![]() |
Combine(String, String) | 将两个字符串组合成一个路径。 |
![]() ![]() |
Combine(String, String, String) | 将三个字符串组合成一个路径。 |
![]() ![]() |
Combine(String, String, String, String) | 将四个字符串组合成一个路径。 |
![]() ![]() ![]() |
GetDirectoryName | 返回指定路径字符串的目录信息。 |
![]() ![]() ![]() |
GetExtension | 返回指定的路径字符串的扩展名。 |
![]() ![]() ![]() |
GetFileName | 返回指定路径字符串的文件名和扩展名。 |
![]() ![]() ![]() |
GetFileNameWithoutExtension | 返回不具有扩展名的指定路径字符串的文件名。 |
![]() ![]() ![]() |
GetFullPath | 返回指定路径字符串的绝对路径。 |
![]() ![]() |
GetInvalidFileNameChars | 获取包含不允许在文件名中使用的字符的数组。 |
![]() ![]() ![]() |
GetInvalidPathChars | 获取包含不允许在路径名中使用的字符的数组。 |
![]() ![]() ![]() |
GetPathRoot | 获取指定路径的根目录信息。 |
![]() ![]() |
GetRandomFileName | 返回随机文件夹名或文件名。 |
![]() ![]() |
GetTempFileName | 创建磁盘上唯一命名的零字节的临时文件并返回该文件的完整路径。 |
![]() ![]() |
GetTempPath | 返回当前系统的临时文件夹的路径。 |
![]() ![]() ![]() |
HasExtension | 确定路径是否包括文件扩展名。 |
![]() ![]() ![]() |
IsPathRooted | 获取一个值,该值指示指定的路径字符串是包含绝对路径信息还是包含相对路径信息。 |