0

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?

Jabberwocky
  • 48,281
  • 17
  • 65
  • 115
lalelu
  • 103
  • 9
  • Try to press F5 to force Explorer to refresh it's file list. – Jabberwocky Nov 19 '14 at 12:12
  • I tried, there is the new date. – lalelu Nov 19 '14 at 12:54
  • 1
    There are many possible reasons, but the primary one that barks from your snippet is you fumbling the time comparison. Convert the FILETIME to a `unsigned long long` first. Check [this question](http://stackoverflow.com/questions/1566645/filetime-to-int64). – Hans Passant Nov 19 '14 at 13:16

0 Answers0