this slowpoke moves

Get File Last Access Time

function GetFileLastAccessTime(sFileName: string): TDateTime;
var
  ffd : TWin32FindData;
  dft : DWord;
  lft : TFileTime;
  h   : THandle;
begin
  // get file information
  h := Windows.FindFirstFile(PChar(sFileName), ffd);
  if INVALID_HANDLE_VALUE <> h then
  begin
    // we're looking for just one file, so close our "find"
    Windows.FindClose(h);

    // convert the FILETIME to local FILETIME
    FileTimeToLocalFileTime(ffd.ftLastAccessTime, lft);

    // convert FILETIME to DOS time
    FileTimeToDosDateTime(lft, LongRec(dft).Hi, LongRec(dft).Lo);

    // finally, convert DOS time to TDateTime for use in Delphi's
    // native date/time functions
    Result := FileDateToDateTime(dft);
  end;
end;
Beispiel :
procedure TForm1.Button1Click(Sender: TObject);
begin
  MessageDlg('c:\config.sys was last accessed on '
    + DateTimeToStr(GetFileLastAccessTime('c:\config.sys')), // HIER DIE DATEI AUF DIE ZUGEGRIFFEN WERDEN SOLL
    mtInformation, [mbOk], 0);
end;

Keine Kommentare:

Kommentar veröffentlichen

Beliebte Posts

Translate