GetFileTime獲得檔案的時間資訊

2021-06-20 03:48:38 字數 1309 閱讀 8212

1

bool winapi getfiletime(

2 __in handle hfile, //

檔案或目錄控制代碼

3 __out_opt lpfiletime lpcreationtime, //

返回的建立的日期和時間資訊

4 __out_opt lpfiletime lplastaccesstime, //

返回的最後訪問的日期和時間資訊

5 __out_opt lpfiletime lplastwritetime //

返回的最後修改的日期和時間資訊

67 );

eg:

handle hfile = createfile(_t("test.txt"),              

generic_write| generic_read,//必須有generic_read屬性才能得到時間

file_share_read,

null,

truncate_existing,

file_attribute_normal,

null);

if(hfile == invalid_handle_value)

return 1;

filetime fcreatetime, faccesstime, fwritetime, localtime;

getfiletime(hfile, &fcreatetime, &faccesstime, &fwritetime);//獲取檔案時間

systemtime systime;

filetimetolocalfiletime(&fcreatetime,&localtime);//將檔案時間轉換為本地檔案時間

filetimetosystemtime(&localtime, &systime);//將本地檔案時間轉換為本地系統時間

cstring strtime;

strtime.format(_t("檔案建立時間為%4d年%2d月%2d日,%2d:%2d:%2d"),

systime.wyear,

systime.wmonth,

systime.wday,

systime.whour,

systime.wminute,

systime.wsecond

);afxmessagebox(strtime);//"檔案建立時間為2023年 1月10日,13:57: 3"

獲得檔案路徑

1 獲得絕對路徑 eg.c yuanzhenhai littlesea.txt 2 當前相對路徑 eg.littlesea.txt 3 獲得目錄上一層的相對路徑 假如已經知道當前路徑是.littlesea.txt 得到它的上一層路徑yuanzhenhai中的xiaohai.txt路徑的方法是 eg....

獲得檔案基本路徑

private string path public string getbasepath catch ioexception e return path public void setpath string path public void run string branch,string fil...

stat 獲得檔案資訊

include include include include include include int main output some of the statistics printf file size ld n buf.st size printf drive c n buf.st dev a...