C#中的文件路徑獲取函數(shù)和文件名字獲取函數(shù)小結(jié)
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. 獲取文件名字(得到指定路徑內(nèi)的文件名,不包括擴展名)
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)
相關(guān)文章
淺談C#在網(wǎng)絡(luò)波動時防重復(fù)提交的方法
這篇文章主要介紹了淺談C#在網(wǎng)絡(luò)波動時防重復(fù)提交的方法,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧2019-04-04C#使用opencv截取旋轉(zhuǎn)矩形區(qū)域圖像的實現(xiàn)示例
這篇文章主要介紹了C#使用opencv截取旋轉(zhuǎn)矩形區(qū)域圖像,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧2021-03-03C#中Dictionary<TKey,TValue>排序方式的實現(xiàn)
這篇文章主要介紹了C#中Dictionary<TKey,TValue>排序方式的實現(xiàn),文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧2021-02-02