Последнее время доступа включает в себя последний раз, когда файл или каталог записывался в , считывался из или, в случае исполняемых файлов, выполнялся .
Другие операции, такие как доступ к файлу для получения свойств, отображаемых в Проводнике или в другом средстве просмотра, доступ к файлу для получения его значка и т. Д. c. не обновлять время последнего доступа.
См. "GetFileTime
- lpLastAccessTime
", " Как получить доступ к файлу без обновления времени последнего доступа?"
Обновление: Добавить результаты теста чтения / записи 0 байтов и чтения / записи 1 байта.
Код, использованный для тестирования:
void GetLastAccessTime(HANDLE hFile)
{
FILETIME ftAccess;
SYSTEMTIME stUTC, stLocal;
printf("Get last access time\n");
// Retrieve the file times for the file.
if (!GetFileTime(hFile, NULL, &ftAccess, NULL))
return;
// Convert the last-write time to local time.
FileTimeToSystemTime(&ftAccess, &stUTC);
SystemTimeToTzSpecificLocalTime(NULL, &stUTC, &stLocal);
// Build a string showing the date and time.
wprintf(
L"%02d/%02d/%d %02d:%02d \n",
stLocal.wMonth, stLocal.wDay, stLocal.wYear,
stLocal.wHour, stLocal.wMinute);
}
int main()
{
HANDLE tFile = INVALID_HANDLE_VALUE;
printf("Open file\n");
// Open file
tFile = CreateFile(L"C:\\Users\\ritah\\Desktop\\test1.txt", GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL);
if (INVALID_HANDLE_VALUE == tFile)
{
printf("CreateFile fails with error: %d\n", GetLastError());
getchar();
return 0;
}
printf("Sleep 60 seconds\n");
Sleep(60000);
GetLastAccessTime(tFile);
// Read 0 bytes
printf("Read 0 bytes\n");
WCHAR redBuf[10];
DWORD redBytes = 0;
if(!ReadFile(tFile, redBuf, 0, &redBytes, NULL))
{
printf("ReadFile fails with error: %d\n", GetLastError());
getchar();
return 0;
}
printf("Sleep 60 seconds\n");
Sleep(60000);
GetLastAccessTime(tFile);
// Write 0 bytes
printf("Write 0 bytes\n");
WCHAR writeBuf[] = L"write test";
DWORD writeBytes = 0;
if(!WriteFile(tFile, writeBuf, 0, &writeBytes, NULL))
{
printf("WriteFile fails with error: %d\n", GetLastError());
getchar();
return 0;
}
printf("Sleep 60 seconds\n");
Sleep(60000);
GetLastAccessTime(tFile);
getchar();
}
![enter image description here](https://i.stack.imgur.com/gKslh.png)
![enter image description here](https://i.stack.imgur.com/QuxSl.png)
Итак, чтение / запись 0
байт не обновляется время последнего доступа .