DelphiFAQ Home Search:
General :: Windows :: Programming :: Windows with Delphi :: Windows Filesystem
File related questions and answers. File operations, attributes, system dialogs, hard disk handling.

Articles:

This list is sorted by recent document popularity (not total page views).
New documents will first appear at the bottom.

Only the 40 most recently viewed articles are shown.
You can see the full list here.

Featured Article

Retrieve a file's 'Last Accessed' attribute

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 := ''; { never :-) }
   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;

Generated 12:02:33 on Jun 24, 2018