1. 擷取絕對檔案路徑
System.IO.Path.GetFullPath(string path)
string fileName = "myfile.ext";
string path1 = @"mydir";
string path2 = @"\mydir";
string fullPath;
fullPath = Path.GetFullPath(path1);
fullPath = Path.GetFullPath(fileName);
fullPath = Path.GetFullPath(path2);
2. 擷取檔案名稱字(得到指定路徑內的檔案名稱,不包括副檔名)
System.IO.Path.GetFileNameWithoutExtension(string path)
string fileName = @"C:\mydir\myfile.ext";
string path = @"C:\mydir\";
string result;
result = Path.GetFileNameWithoutExtension(fileName);
result = Path.GetFileName(path);
3.獲得包含 path 目錄資訊的string 或者為空白引用
System.IO.Path.GetDirectoryName(string path)
string fileName = @"C:\mydir\myfile.ext";
string path = @"C:\mydir\";
string rootPath = @"C:\";
string directoryName;
directoryName = Path.GetDirectoryName(fileName);
directoryName = Path.GetDirectoryName(path);
directoryName = Path.GetDirectoryName(rootPath);
4.合并兩個路徑字串。
System.IO.Path.Combine(String path1, String path2)