Get 'Last Accessed' attribute of a file  

Send By: Q3 Team
Web : http://www.q3.nu
Email: dlib@q3.nu
Date: 08/08/99

Tip accessed 503 times

 


In the info showed when right click over a file, with title 'Last Accessed'.

  • Put a TLabel (Label1) and a TButton (Button1) in your form
  • In the OnClick of Button1 put this code:


     procedure TForm1.Button1Click(Sender: TObject);
     var
       FileHandle : THandle;
       LocalFileTime : TFileTime;
       DosFileTime : DWORD;
       LastAccessedTime : TDateTime;
       FindData : TWin32FindData;
     begin
       FileHandle := FindFirstFile('c:\directorio\UnFichero.txt', FindData);
       if FileHandle <> INVALID_HANDLE_VALUE then
       begin
         Windows.FindClose(Handle);
         if (FindData.dwFileAttributes and FILE_ATTRIBUTE_DIRECTORY) = 0 then
         begin
           FileTimeToLocalFileTime(FindData.ftLastAccessTime, LocalFileTime);
           FileTimeToDosDateTime(LocalFileTime,
           LongRec(DosFileTime).Hi,LongRec(DosFileTime).Lo);
           LastAccessedTime := FileDateToDateTime(DosFileTime);
           Label1.Caption := DateTimeToStr(LastAccessedTime);
         end;
       end;
     end;