...get the modify date of files?

Author: Rainer Kümmerle
Homepage: http://www.thinklazy.de

Category: Files

function GetFileModifyDate(FileName: string): TDateTime;
var
  
h: THandle;
  Struct: TOFSTRUCT;
  lastwrite: Integer;
  t: TDateTime;
begin
  
h := OpenFile(PChar(FileName), Struct, OF_SHARE_DENY_NONE);
  try
    if 
h <> HFILE_ERROR then
    begin
      
lastwrite := FileGetDate(h);
      Result    := FileDateToDateTime(lastwrite);
    end;
  finally
    
CloseHandle(h);
  end;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  if 
Opendialog1.Execute then
    
label1.Caption := FormatDateTime('dddd, d. mmmm yyyy hh:mm:ss',
      GetFileModifyDate(Opendialog1.FileName));
end;

 

printed from
www.swissdelphicenter.ch
developers knowledge base