using System.IO;
取得程式當下檔案目錄資訊: string sPath = this.GetType().Assembly.Location;
string filename = @"C:\Users\123.text"; if (File.Exists(filename)) { MessageBox.Show("取得檔名(不包含附檔名)" + Path.GetFileNameWithoutExtension(filename)); MessageBox.Show("取得副檔名:" + Path.GetExtension(filename)); MessageBox.Show("目錄資料夾路徑:" + Path.GetDirectoryName(filename)); MessageBox.Show("資料根目錄:" + Path.GetPathRoot(filename)); MessageBox.Show("取得路徑:" + Path.GetFullPath(filename)); }
測試環境:c#.net 2015
沒有留言:
張貼留言