现在的位置: 首页 > 综合 > 正文

获得文件最后修改日期

2013年10月24日 ⁄ 综合 ⁄ 共 882字 ⁄ 字号 评论关闭

// 获取最后修改的文件时间
BOOL GetLastWriteTime(HANDLE hFile, LPSTR lpszString)
{
    FILETIME ftCreate, ftAccess, ftWrite;
    SYSTEMTIME stUTC, stLocal;

    // Retrieve the file times for the file.
    if (!GetFileTime(hFile, &ftCreate, &ftAccess, &ftWrite))
        return FALSE;

    // Convert the last-write time to local time.
    FileTimeToSystemTime(&ftWrite, &stUTC);

 // 转换为本地时间
    SystemTimeToTzSpecificLocalTime(NULL, &stUTC, &stLocal);

    // Build a string showing the date and time.
    wsprintf(lpszString, "%02d/%02d/%d  %02d:%02d",
        stLocal.wDay, stLocal.wMonth, stLocal.wYear,
        stLocal.wHour, stLocal.wMinute);

    return TRUE;
}
 

// 如下调用此可获得
HANDLE hFind = CreateFile("c://1.exe",GENERIC_WRITE,FILE_SHARE_WRITE,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL);

 HANDLE hFind = CreateFile(sss,GENERIC_WRITE,FILE_SHARE_WRITE,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL);

  char chMsg[MAX_PATH];

  GetLastWriteTime (hFind,chMsg);
  AfxMessageBox(chMsg);

抱歉!评论已关闭.