Number of days between two filetime structures...
I'm basically trying to see if a file is a certain number of days old, so that I can delete it... the code so far looks like:
Code:
FILETIME ft;
FILETIME ftFile;
bFinished = FALSE;
_snprintf(szSearch, sizeof(szPath), "%s\\*.*", szPath);
hSearch = FindFirstFile(szSearch, &wfd);
if (hSearch == INVALID_HANDLE_VALUE)
return FALSE;
while (!bFinished) {
if (!(wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) {
_snprintf(szFileName, sizeof(szFileName),
"%s\\%s", szPath, wfd.cFileName);
GetSystemTimeAsFileTime(&ft);
ftFile.dwHighDateTime = wfd.ftLastWriteTime.dwHighDateTime;
ftFile.dwLowDateTime = wfd.ftLastWriteTime.dwLowDateTime;
LocalFileTimeToFileTime(&(wfd.ftLastWriteTime));
/*NEED TO COMPARE HERE */
if (!DeleteFile(szFileName)) {
;
}
}
if (!FindNextFile(hSearch, &wfd)) {
if (GetLastError() == ERROR_NO_MORE_FILES) {
bFinished = TRUE;
}
else {
;
break;
}
}
}
if (!FindClose(hSearch)) {
;
}
return TRUE;
This code is not complete I know ... I need to be able to tell how many days old the file is, how do i get this from two FILETIME objects??
Re: Number of days between two filetime structures...
One solution is GetFileInformationByHandle().
Kuphryn
Re: Number of days between two filetime structures...
Code:
FILETIME ft1, ft2;
COleDateTime ot1(ft1);
COleDateTime ot2(ft2);
COleDateTimeSpan otspan = ot2-ot1;
otspan.GetTotalDays();