MFC從檔案路徑獲取檔名和檔案型別

2021-09-25 08:04:19 字數 730 閱讀 3373

mfc中有時候需要根據獲取的檔案路徑資訊來擷取檔名,或者檔案型別

已知檔案路徑:cstring firstfilepath = "d:\wang jw\greatwall\hexfileencrypt\file_test\sunroof_iap_9843_2.hex";

1、檔名獲取方式為:

cstring firstfilename = "";

firstfilename = firstfilepath.right(firstfilepath.getlength()-firstfilepath.reversefind('\\')-1);//從路徑中擷取檔名

結果:firstfilename = "sunroof_iap_9843_2.hex"

去掉檔案的字尾,只要檔名:

firstfilename = firstfilename.left(firstfilename.find('.')); //去除字尾

結果:firstfilename = "sunroof_iap_9843_2"

2、檔案字尾獲取方式為:

cstring firstfilesuffix = "";

//獲取檔案的字尾

firstfilesuffix = firstfilepath.right(firstfilepath.getlength()-firstfilepath.reversefind('.')-1);

結果: firstfilesuffix = "hex"

獲取檔名和檔案路徑

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 這些 怎麼用,怎麼用,怎麼用!看著這種 就氣不打一處來,換個資料怎麼辦,在 裡改?假設我現在想每開啟乙個檔案,就對應建立...