2.1.8.2 CompareFileTime


Description

compares two 64-bit file times

Syntax

LONG CompareFileTime( const FILETIME * lpFileTime1, const FILETIME * lpFileTime2 )

Parameters

lpFileTime1
[input] pointer to the first file time
lpFileTime2
[input] pointer to the second file time

Return

-1 First file time is less than second file time.

0 First file time is equal to second file time.

+1 First file time is greater than second file time.

Examples

EX1

// Note that the file c:\myfile.txt must exist for this example to run.
int CompareFileTime_ex1()
{
    string                        strFile = "c:\\myfile.txt";
    if(!strFile.IsFile())
    {
        HANDLE hFile = CreateFile(strFile, GENERIC_WRITE, FILE_SHARE_READ, NULL, CREATE_NEW, FILE_ATTRIBUTE_NORMAL, NULL);
        if (hFile != INVALID_HANDLE_VALUE)
        {
            CloseHandle(hFile);
        }
    }
     WIN32_FILE_ATTRIBUTE_DATA    fileInfo;
    // Get the attributes structure of the file
    if ( GetFileAttributesEx(strFile, 0, &fileInfo) )
    {
        int        nCompare = CompareFileTime(&fileInfo.ftLastAccessTime, &fileInfo.ftLastWriteTime);
        if (nCompare < 0)
            out_str("Last access time is less than last write time");
        else if (0 == nCompare)
            out_str("Last access time is the same as last write time");
        else
            out_str("Last access time is greater than last write time");
    }
    else
        out_str("Cannot get file attributes!");
    return 1;
}

Remark

See Also

Header to Include

origin.h

Reference