-
string filePath = "C:\\1.txt";
-
string str = "獲取文件的全路徑:" + Path.GetFullPath(filePath); //-->C:1.txt
-
str = "獲取文件所在的目錄:" + Path.GetDirectoryName(filePath); //-->C:
-
Console.WriteLine(str);
-
str = "獲取文件的名稱含有后綴:" + Path.GetFileName(filePath); //-->1.txt
-
str = "獲取文件的名稱沒有后綴:" + Path.GetFileNameWithoutExtension(filePath); //-->1
-
str = "獲取路徑的后綴擴展名稱:" + Path.GetExtension(filePath); //-->.txt
-
str = "獲取路徑的根目錄:" + Path.GetPathRoot(filePath); //-->C:\