using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; namespace TBQDLKW { class Program { static void Main(string[] args) { //一個文件目錄 string filePath = @"C:\Users\JuYaNan\Desktop\DBCs\ST_CAN.dbc"; Console.WriteLine("該文件的目錄:" + filePath); string str = "獲取文件的全路徑:" + Path.GetFullPath(filePath); Console.WriteLine(str); str = "獲取文件所在的目錄:" + Path.GetDirectoryName(filePath); Console.WriteLine(str); str = "獲取文件的名稱含有后綴:" + Path.GetFileName(filePath); Console.WriteLine(str); str = "獲取文件的名稱沒有后綴:" + Path.GetFileNameWithoutExtension(filePath); Console.WriteLine(str); str = "獲取路徑的后綴擴展名稱:" + Path.GetExtension(filePath); Console.WriteLine(str); str = "獲取路徑的根目錄:" + Path.GetPathRoot(filePath); Console.WriteLine(str); Console.ReadKey(); } } }
結果圖: