獲取檔案的字尾名

2021-07-03 18:57:35 字數 713 閱讀 8287

使用api   pathfindextension實現獲取給定乙個檔案,直接獲取檔案的字尾名

如:檔名 hsduiew.txt ; jhdsi.adiwey ;路徑+檔名 :c:\hsh\shsh\tetet.txt

都可以直接獲取到字尾名。

pathfindextension函式說明:

函式原型:ptstr pathfindextension( _in_ ptstr pszpath);

引數:指向以0結尾,最大長度為max_path檔案路徑字串指標。

函式說明:獲取絕對路徑或檔名中的副檔名。

返回值:

如果副檔名找到則返回pszpath字串中「.」所在位址,否則返回空字元結尾位址。

#include

#include

#include

#pragma comment(lib,"shlwapi.lib")

using namespace std;

int main()

獲取檔案字尾名

獲取到filename的字尾 利用lastindexof 從最後面截字尾,找到最後乙個點的索引然後加一,利用substring擷取該索引後的字串 f.getfilename substring f.getfilename lastindexof 1 lastindexof 方法有以下四種形式 pub...

java獲取檔案字尾名

獲取檔案字尾名 public static string endwith string filename return result 可以放到工程的工具類裡直接呼叫,需要注意的是string token filename.split 一定要用轉義字元,因為spilt裡面有一定的正規表示式在裡面 發現...

PHP 獲取檔案字尾名

1.file x.y.z.png echo substr strrchr file,1 解析 strrchr file,strrchr 函式查詢字串在另乙個字串中最後一次出現的位置,並返回從該位置到字串結尾的所有字元 2.file x.y.z.png echo substr file,strrpos...