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