Trying to change the FileDates

4 views
Skip to first unread message

Micha68

unread,
Sep 25, 2022, 4:56:36 AM9/25/22
to Win32 Programming
Hi,
i was jut asked by a freind, Could you write a program that changes the Times-Stamp of a File?
E.g. Change the Time of Creation, the Time of Lastmodified and Lastaccessed?

So, my answer was Yes, sure.
But, changing the Timestamp for a singel file works perfectly as I thought. Changing the Timestamp for multiple Files (in a findfile...findnext Construction) fails.
Why?

sysTime predefined;

            hFind = FindFirstFile("D:\\Temp57\\*.*", &fd);
            while (hFind != INVALID_HANDLE_VALUE && bRet)
            {
                if ((fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) == 0)
                {
                    SystemTimeToFileTime(&sysTime, &fLocTime);
                    LocalFileTimeToFileTime(&fLocTime, &fTime);
                    hFile = CreateFile(fd.cFileName, GENERIC_READ | GENERIC_WRITE, 0 ,NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_NO_BUFFERING, NULL);
                    SetFileTime(hFile, &fTime, &fTime, &fTime);
                    CloseHandle(hFile);
                }
                bRet = FindNextFile(hFind, &fd);
            }
            FindClose(hFind);
            break;

Any Idea is welcome.
Reply all
Reply to author
Forward
0 new messages