I tested this on windows xp.
If I do
- Create a file.
- Write to the file.
- Close the file.(Then, the file's LastWriteTime is changed)
But if I do
- Create a file.
- Set LastFileTime of the file.
- Examine the time by calling GetFileTime (Then, the file's LastWriteTime is changed)
- Sleep 20 seconds.
- Write to the file.
- Sleep 20 seconds.
- Close the file.
- Examine the time by calling GetFileTime (The process5's time is never applied. Why?)
Edit:
wstring fileName = L"D:\\testfile.txt";
HANDLE h = CreateFileW(fileName.c_str(), GENERIC_WRITE | GENERIC_READ,
FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
0,
CREATE_ALWAYS,
0, 0);
FILETIME ft1, ft2, ft3;
if(!GetFileTime(h, &ft1, &ft2, &ft3))
{
return;
}
std::cout << ft3.dwHighDateTime << std::endl << ft3.dwLowDateTime << std::endl;
ft1.dwLowDateTime = 1000000;
if(!SetFileTime(h, &ft1, &ft1, &ft1))
{
return;
}
if(!GetFileTime(h, &ft1, &ft2, &ft3))
{
return;
}
std::cout << ft3.dwHighDateTime << std::endl << ft3.dwLowDateTime << std::endl;
Sleep(5000);
TCHAR buffer[] = L"Test1234567890 Test1234567890 Test1234567890 Test1234567890 Test1234567890\r\n";
DWORD writeBytes = 0;
BOOL fOk = WriteFile(h, buffer, sizeof(buffer), &writeBytes, 0);
if(!fOk)
{
return;
}
if(writeBytes != sizeof(buffer))
{
return;
}
if(!GetFileTime(h, &ft1, &ft2, &ft3))
{
return;
}
std::cout << ft3.dwHighDateTime << std::endl << ft3.dwLowDateTime << std::endl;
CloseHandle(h);
h = CreateFileW(fileName.c_str(), GENERIC_WRITE | GENERIC_READ,
FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
0,
OPEN_EXISTING,
0, 0);
if(!GetFileTime(h, &ft1, &ft2, &ft3))
{
return;
}
std::cout << ft3.dwHighDateTime << std::endl << ft3.dwLowDateTime << std::endl;
CloseHandle(h);
DeleteFile(fileName.c_str());
Could you explain me about this? Thanks.