2.1.8.12 GetFileTime


Description

This function retrieves the file creation time, last access time, last write time.

Syntax

BOOL GetFileTime( HANDLE hFile, FILETIME * lpCreationTime, FILETIME * lpLastAccessTime, FILETIME * lpLastWriteTime )

Parameters

hFile
[input] Handle to the file for which to set the dates and times. The file handle must have been created with GENERIC_WRITE access to the file.
lpCreationTime
[output] FILETIME structure that contains the date and time the file was created. This parameter can be NULL if the application does not need to set this information.
lpLastAccessTime
[output] FILETIME structure that contains the date and time the file was last accessed. The last access time includes the last time the file was written to, read from, or (in the case of executable files) run. This parameter can be NULL if the application does not need to set this information.
lpLastWriteTime
[output] FILETIME structure that contains the date and time the file was last written to. This parameter can be NULL if the application does not want to set this information.

Return

TRUE if success, FALSE if error

Examples

EX1

int GetFileTime_ex1()
{
    char* szFilename = "c:\\test.txt" ;
    BOOL bRet = FALSE;
    HANDLE hFile = CreateFile(szFilename, GENERIC_WRITE, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
    if (hFile != INVALID_HANDLE_VALUE)
    {
        FILETIME ftCreation;
        FILETIME ftLastAccessTime;
        FILETIME ftLastWrite;
        bRet = GetFileTime(hFile,&ftCreation, &ftLastAccessTime, &ftLastWrite);
        CloseHandle(hFile);
    }
    return 1;
}

Remark

See Also

SetFileTime, FileTimeToSystemTime, SystemTimeToJulianDate

Header to Include

origin.h

Reference