C 檔案路徑獲取函式和檔案名字獲取函式

2021-09-08 07:30:03 字數 1110 閱讀 7382

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)

獲取檔名和檔案路徑

1.問題描述 比如已經知道檔案的路徑是 c dir0 dir1 readme.txt 除了用split 的方式獲取檔名和路徑,有沒有什麼更高效的方式 2.解決辦法 os.path.dirname 路徑 os.path.basename 檔名 import os file path d work te...

QT 獲取檔案路徑和檔名

這篇部落格來說一下在qt中如何獲取檔名和檔案路徑 主要用到了qfileinfo這個類,下面以 示例來說明 qstring file,file name,file path qfileinfo fi file qfiledialog getopenfilename this 這一行獲取的是檔案選擇框選...

QT中獲取檔案路徑和檔名

我發現各種教程都有乙個毛病,就是愛把資料寫死在 裡,比如建個資料庫 sqlite3.connect test.db 插入個資料insert into user values 12 這些 怎麼用,怎麼用,怎麼用!看著這種 就氣不打一處來,換個資料怎麼辦,在 裡改?假設我現在想每開啟乙個檔案,就對應建立...