2

我想检查一个文件夹是否大于 30 天并具有以下代码

static bool ExpiredDirectory(CComBSTR directory)
{
    WIN32_FILE_ATTRIBUTE_DATA fileAttrData = {0};
    GetFileAttributesEx(directory, GetFileExInfoStandard, &fileAttrData);

    FILETIME ftCreatedDate = fileAttrData.ftCreationTime;
    FILETIME now;
    SYSTEMTIME nowst;
    ULARGE_INTEGER t1, t2;
    GetSystemTime(&nowst);
    SystemTimeToFileTime(&nowst, &now);

      ---compare code goes here

}

我想比较上面的变量,看看 ftCreatedDate 是否大于 30 天

4

1 回答 1

1

我在 SYSTEMTIME的 30 天差异的帮助下解决了这个问题。原来这个人也想做几乎一样的事情。应该以前看过这个

我的代码现在是

WIN32_FILE_ATTRIBUTE_DATA fileAttrData = {0};
GetFileAttributesEx(directory, GetFileExInfoStandard, &fileAttrData);
FILETIME ftCreationTime = fileAttrData.ftCreationTime;
FILETIME now;
SYSTEMTIME nowst;
ULARGE_INTEGER t1, t2;

GetSystemTime(&nowst);
SystemTimeToFileTime(&nowst, &now);

memcpy(&t1, &ftCreationTime, sizeof(t1));
memcpy(&t2, &now, sizeof(t1));
ULONGLONG diff = (t1.QuadPart<t2.QuadPart)?(t2.QuadPart-t1.QuadPart):(t1.QuadPart-t2.QuadPart);

if(diff>30*24*60*60*(ULONGLONG)10000000)
{
    return true;
}

return false;
于 2013-05-02T14:32:22.640 回答