Windows 一些常用到的檔案路徑相關的API

2021-09-10 07:49:03 字數 4815 閱讀 3519

需要標頭檔案:shlwapi.h

其中有一些函式功能存在重複,我在認為比較常用的的函式上加紅。

bool pathfileexists(lpctstr lpszpath)
功能:檢查檔案/路徑是否存在

lptstr pathfindfilename(lpctstr ppath)
功能:獲得路徑中的檔名

例如: pathfilefilename( 「c://program files ) = 「file.txt」。

如果路徑中不包含檔名,則返回值是最下面的目錄名。

lptstr pathfindextension(lpctstr ppath)
功能:獲取路徑或檔名中的副檔名

例如:pathfindextension( 「file.txt」 ) = 「.txt」

lptstr pathfindnextcomponent(lpctstr pszpath)
例如:pathfindnextcomponent( 「c://program files//directory」 ) = 「program files//

directory」

pathfindnextcomponent( 「c://program files」 ) = 「program files」

bool pathfindonpath( in out lptstr pszfile , in lpctstr * ppszotherdirs)
功能:在指定的目錄中尋找檔案。

引數:pszfile 要尋找的檔名,確保 pszfile 有足夠的大小來容納 max_path 個字元。如果能找到指定的檔案,該引數將返回檔案的全路徑。

ppszotherdirs該引數是首先要尋找的目錄列表,它可以為null,如果為null,函式將在系統目錄,當前目錄和由path設定的目錄中查詢。

lptstr pathgetargs(lpctstr pszpath)
功能:從路徑中分析引數

例如:lptstr pszparam = pathgetargs( 「notepad.exe c: )

pszparam 返回 「c:

int pathgetdrivenumber(lpctstr lpsz)
功能:從路徑中分析碟符

返回值:成功返回 0 –25 ,代表(a – z),失敗返回 –1

bool pathiscontenttype(lpctstr pszpath,lpctstr pszcontenttype)
功能:檢查檔案是否為指定的contenttype

例如:pathiscontenttype( 「hello.txt」 , 「text/plain」 ) 返回true

pathiscontenttype( 「hello.txt」 , 「image/gif」 ) 返回false

bool pathisdirectory(lpctstr pszpath)
功能:檢查路徑是否為有效目錄。注意路徑不能包含檔名

bool pathisfilespec(lpctstr lpszpath)
功能:檢查路徑中是否帶有 『:』 和 『/』 分隔符

bool pathishtmlfile(lpctstr pszfile)
功能:檢查是否為html檔案

bool pathisprefix(in lpctstr pszprefix,in lpctstr pszpath)
功能:檢查路徑是否包含指定字首,字首如:」碟符://」 、「…//」 、」.//」

pathisprefix ( 「c://」 , 「c: ) 返回 true

bool pathisrelative(lpctstr lpszpath)
功能:檢查路徑是否是相對路徑

bool pathisroot(lpctstr ppath)
功能:檢查路徑是否是根目錄

bool pathissameroot(lpctstr pszpath1,lpctstr pszpath2);
功能:比較兩個路徑是否在同一碟符

bool pathisunc(lpctstr pszpath );
功能:判斷路徑是否是unc格式

bool pathisurl(in lpctstr pszpath );
功能:判斷路徑是否是url

bool pathmatchspec( lpctstr pszfileparam,lpctstr pszspec)
功能:用帶有萬用字元(號和?號)的字串去比較另乙個字串

例如:pathmatchspec( 「 , 「sina.com

」 ) 返回true

pathmatchspec( 「c: , 「.txt」 ) 返回true

void pathremoveargs(lptstr pszpath);
功能:刪除路徑中帶有的引數

lptstr pathremovebackslash(lptstr lpszpath);
功能:刪除路徑結尾多餘的』/』符號

void pathremoveblanks(lptstr lpszstring);
功能:刪除字串頭尾的空格

void pathremoveextension( lptstr pszpath);
功能:刪除路徑後面的副檔名

bool pathremovefilespec( lptstr pszpath);
功能:刪除路徑後面的檔名和』/』符號。該函式可以分析出乙個檔案的路徑。

例:szpath = 「c://windows//system32 ;

呼叫pathremovefilespec( szpath ) 後,szpath = 「c://windows//system32」

bool pathrenameextension( in out lptstr pszpath,lpctstr pszext);
功能:替換路徑後面的副檔名,如果pszpath後面不帶副檔名,則新的副檔名會被新增上去。

pszpath pszpath至少需要max_path個字元的空間

pszext 新的副檔名,必需包含 . 號

void pathstrippath(lptstr pszpath );
功能:從路徑中分析出檔名

例: pathstrippath( 「c://test ) => hello.txt

bool pathstriptoroot( lptstr szroot );
功能:從路徑中分析出碟符

void pathunquotespaces( lptstr lpsz );
功能:從帶引號的路徑中取出路徑

例:szpath = 「/」c://program files/」」

pathunquotespaces( szpath ) => szpath = 「c://program files」

附另一路徑相關函式,由imagehlp提供

bool searchtreeforfile(

in lpstr rootpath,

in lpstr inputpathname,

out lpstr outputpathbuffer

);

功能:從指定目錄樹中尋找檔案

strchr ,strchri,strcmpn,strcmpni,strcspn,strcspni,strdup,strformatbytesize(位元組大小格式化),strfromtimeinterval,strisintlequal,strncat,strpbrk,strrchr,strrchri,strrstri,strspn,strstr,strstri,strtoint,strtointex(可以講16進製制字串轉換為10進製值),strtrim(刪除收尾空字串),strcat,strcmp,strcpy,chrcmpi,

shdeleteemptykey,shdeletekey,shdeletevalue,shgetvalue,shsetvalue,shqueryvalueex,shenumkeyex,shenumvalue,shqueryinfokey,

shregcreateuskey,shregopenuskey,shregqueryusvalue,shregwriteusvalue,shregdeleteusvalue,shregdeleteemptyuskey,shregenumuskey,

shregenumusvalue,shregqueryinfouskey,shreggetusvalue,shregsetusvalue,shreggetboolusvalue,shopenregstream,

建立gdi幫助函式

shcreateshellpalette

dllgetversionproc指標,用來獲取dll的版本號

和dllinstall原型定義

stdapi dllinstall(bool binstall, lpcwstr pszcmdline);

centos經常用到的一些檔案

主機名檔案 etc sysconfig network 網路ip配置檔案 etc sysconfig network scripts ifcfg eth0 shell執行載入的指令碼檔案 工作目錄下 bash profile 系統啟動全域性 指令碼檔案 etc profile linux系統版本 e...

centos經常用到的一些檔案

主機名檔案 etc sysconfig network 網路ip配置檔案 etc sysconfig network scripts ifcfg eth0 shell執行載入的指令碼檔案 工作目錄下 bash profile 系統啟動全域性 指令碼檔案 etc profile linux系統版本 e...

經常用到的一些函式

1.對話方塊函式 showmessage 用於在程式執行過程中顯示乙個包含乙個字串資訊的對話方塊,使用者只有對這個對話方塊準確響應後才能關閉對話方塊,進行下一步工作。語法結構 showmessage const msg string showmessage hello delphi messaged...