(page requirements)

When was that file last accessed?

Here's an example of how to write a function that'll return a file's last access time (not to be confused with the last modified time).
function GetFileLastAccessTime(
  sFileName : string ) : TDateTime;
  ffd : TWin32FindData;
  dft : DWord;
  lft : TFileTime;
  h   : THandle;
  // get file information
  h := Windows.FindFirstFile(
         PChar(sFileName), ffd);
    // we're looking for just one file,
    // so close our "find"
    Windows.FindClose( h );
    // convert the FILETIME to
    // local FILETIME
      ffd.ftLastAccessTime, lft );
    // convert FILETIME to
    // DOS time
    LongRec(dft).Hi, LongRec(dft).Lo);
    // finally, convert DOS time to
    // TDateTime for use in Delphi's
    // native date/time functions
    Result := FileDateToDateTime(dft);
Listing #1 : Delphi code. Download fatime (0.53 KB).
"GetFileLastAccessTime()" will return a given file's last access time as a Delphi "TDateTime" type which you can convert to a string by using the "DateTimeToStr()" function. For example:
    'c:config.sys was last accessed on ' +
      GetFileLastAccessTime( 'c:config.sys' ) ),
    mtInformation, [mbOk], 0 );
Listing #2 : Delphi code. Download sample (0.25 KB).
Applicable Keywords : Delphi, Delphi 2.x, Delphi 3.x, Functions, Win32
Copyright © 2009 Chami.com. All Rights Reserved. | Advertise | Created in HTML Kit editor