[csharp] view plain copy class Program { static void Main(string[] args) { //獲取當前運行程序的目錄 string fileDir = Environment.CurrentDirectory; Console.WriteLine("當前程序目錄:"+fileDir); //一個文件目錄 string filePath = "C:\\JiYF\\BenXH\\BenXHCMS.xml"; Console.WriteLine("該文件的目錄:"+filePath); string str = "獲取文件的全路徑:" + Path.GetFullPath(filePath); //-->C:\JiYF\BenXH\BenXHCMS.xml Console.WriteLine(str); str = "獲取文件所在的目錄:" + Path.GetDirectoryName(filePath); //-->C:\JiYF\BenXH Console.WriteLine(str); str = "獲取文件的名稱含有后綴:" + Path.GetFileName(filePath); //-->BenXHCMS.xml Console.WriteLine(str); str = "獲取文件的名稱沒有后綴:" + Path.GetFileNameWithoutExtension(filePath); //-->BenXHCMS Console.WriteLine(str); str = "獲取路徑的后綴擴展名稱:" + Path.GetExtension(filePath); //-->.xml Console.WriteLine(str); str = "獲取路徑的根目錄:" + Path.GetPathRoot(filePath); //-->C:\ Console.WriteLine(str); Console.ReadKey(); } }