日本免费高清视频-国产福利视频导航-黄色在线播放国产-天天操天天操天天操天天操|www.shdianci.com

學無先后,達者為師

網站首頁 編程語言 正文

C#文件路徑Path類介紹_C#教程

作者:springsnow ? 更新時間: 2022-07-23 編程語言

Path類

以幫助在程序中管理文件和目錄路徑。

Path類位于System.IO命名空間,是一個靜態類,可以用來操作路徑的每一個字段,如驅動器盤符、目錄名、文件名、文件擴展名和分隔符等。

Path類的靜態屬性和方法,此類操作不影響物理文件。

1、屬性

Path類的常用字段成員有PathSeperator(路徑分隔符,如”;”)、DirectorySeparatorChar(目錄分隔符,如”\”)、VolumeSeparator(卷分隔符,如”:”)、AltDirectorySeparator(替換目錄分隔符,如”/”),常用的方法成員有GetDirectoryName(取目錄名)、GetFileName(取文件名)、

char a = System.IO.Path.VolumeSeparatorChar;//  :
char b = System.IO.Path.DirectorySeparatorChar;//  \

2、方法

GetExtension(取文件擴展名)、GetFullPath(取完整路徑)、GetTempPath(取操作系統的臨時文件路徑)等,例如,以下代碼表示提取并顯示路徑中的目錄名和文件名。

string filePath =@”c:\folder\file.txt”;

Path.ChangeExtension(filePath, ".html");// c:\folder\file.htm
Path.Combine("c:\folder", "file.txt");// c:\folder\file.txt
Path.IsPathRooted(filePath);    // true
Path.GetPathRoot(filePath);     // C:\
Path.GetDirectoryName(filePath);// c:\folder
Path.GetFileName(filePath);     // file.txt
Path.GetFileNameWithoutExtension(filePath);// file
Path.HasExtension(filePath);    // true
Path.GetExtension(filePath);    // .txt
Path.GetFullPath(filePath);     // c:\folder\file.txt

原文鏈接:https://www.cnblogs.com/springsnow/p/10346229.html

欄目分類
最近更新