I want to download a file from a server if it´s newer then the one on my disc.
I wrote following code:
bool bDownload = true;
HANDLE hFile = CreateFile(strFileLocal, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL);
if (hFile != INVALID_HANDLE_VALUE)
{
FILETIME ftLocal = { 0 };
FILETIME ftWrite = { 0 }; // only for testing
GetFileTime(hFile, &ftLocal, NULL, &ftWrite);
FILETIME ftRemote = arrTimes[i]; //get size from server
if (ftLocal.dwLowDateTime >= ftRemote.dwLowDateTime && ftLocal.dwHighDateTime >= ftRemote.dwHighDateTime)
{
bDownload = false;
}
CloseHandle(hFile);
}
After this is done I download the file and set the filetime from server to the file:
//set file date
HANDLE hFile = CreateFile(strFileLocal, GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL);
if (hFile != INVALID_HANDLE_VALUE)
{
FILETIME ftRemote = arrTimes[i];
SetFileTime(hFile, &ftRemote, NULL, &ftRemote);
CloseHandle(hFile);
}
Now my problem: If I replace the file on disk with a new creation time, GetFileTime will read the time I had set. But in the file explorer in windows the file has the new creation time.
For testing I tried to read last writing time. But this is the same time as creation time. Thanks a lot.
How can I fix this problem? Do I something wrong?