I seem to be running into a problem when attempting to re-create a file. This file contains information that changes on a regular basis, so I currently have it rigged so that if the file's creation date is older than 7 days it gets re-created.
However, I have found that even after re-creation, the file's creation date remains over 7 days in the past. Originally I re-created the file solely by using the CREATE_ALWAYS flag in CreateFile. After discovering this bug I tried adding a DeleteFile call just before it, but no difference.
Short of calling the new version of the file something else or using SetFileTime on it, is there a way that I can make sure dead files stay dead???
Example:- (console mode)
Run this once and make a note of the time given. Wait a few minutes and run it again. Although the file is deleted, when it is re-created it still has the same creation date!
FILETIME ft, ftLocal;
MessageBox(NULL, "File not created yet (run again a few minutes after for result)", NULL, MB_ICONEXCLAMATION);
hFile = CreateFile("test.abc", GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
if (hFile == INVALID_HANDLE_VALUE)
GetFileTime(hFile, &ft, NULL, NULL);
GetDateFormat(LOCALE_USER_DEFAULT, DATE_SHORTDATE, &st, NULL, szCreated, 32);
lstrcat(szCreated, " ");
GetTimeFormat(LOCALE_USER_DEFAULT, 0, &st, NULL, szCreated + lstrlen(szCreated), 32 - lstrlen(szCreated));
MessageBox(NULL, szCreated, NULL, MB_ICONINFORMATION);