Author: William Gerbert
Retrieve a file's "Last Accessed" attribute
Answer:
In Windows 95, you can see when a file was last accessed by right-clicking the file
and selecting properties. You can retrieve this date easily with the following
ready-to-use function:
1 2 function LastAccess(const filename: string): string;
3 var4 FileHandle: THandle;
5 LocalFileTime: TFileTime;
6 DosFileTime: DWORD;
7 LastAccessedTime: TDateTime;
8 FindData: TWin32FindData;
9 begin10 Result := ''; { never :-) }11 FileHandle := FindFirstFile(filename, FindData);
12 if FileHandle <> INVALID_HANDLE_VALUE then13 begin14 Windows.FindClose(Handle);
15 if (FindData.dwFileAttributes and FILE_ATTRIBUTE_DIRECTORY) = 0 then16 begin17 FileTimeToLocalFileTime(FindData.ftLastWriteTime, LocalFileTime);
18 FileTimeToDosDateTime(LocalFileTime,
19 LongRec(DosFileTime).Hi, LongRec(DosFileTime).Lo);
20 LastAccessedTime := FileDateToDateTime(DosFileTime);
21 Result := DateTimeToStr(LastAccessedTime);
22 end;
23 end;
24 end;