Windows with Delphi Windows API (94) Windows Filesystem (41) Windows Forms (69) Windows Graphics (38)
Exchange Links About this site Links to us 
|
Retrieve a file's 'Last Accessed' attribute
This article has not been rated yet. After reading, feel free to leave comments and rate it.
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:
 | |  | |
function LastAccess (const filename : string) : string;
var
FileHandle : THandle;
LocalFileTime : TFileTime;
DosFileTime : DWORD;
LastAccessedTime : TDateTime;
FindData : TWin32FindData;
begin
Result := '';
FileHandle := FindFirstFile(filename, FindData);
if FileHandle <> INVALID_HANDLE_VALUE then
begin
Windows.FindClose(Handle);
if (FindData.dwFileAttributes and FILE_ATTRIBUTE_DIRECTORY) = 0 then
begin
FileTimeToLocalFileTime(FindData.ftLastWriteTime, LocalFileTime);
FileTimeToDosDateTime(LocalFileTime,
LongRec(DosFileTime).Hi,LongRec(DosFileTime).Lo);
LastAccessedTime := FileDateToDateTime(DosFileTime);
Result := DateTimeToStr(LastAccessedTime);
end;
end;
end; | |  | |  |
Comments:
|