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 | 獲取一個值,該值指示指定的路徑字符串是包含絕對路徑信息還是包含相對路徑信息。 |