Task

Get and set the modification time of a file.




function GetModifiedDate(const aFilename: string): TDateTime;
var
  hFile: Integer;
  iDosTime: Integer;
begin
  hFile := FileOpen(aFilename, fmOpenRead);
  iDosTime := FileGetDate(hFile);
  FileClose(hFile);
  if (hFile = -1) or (iDosTime = -1) then raise Exception.Create('Cannot read file: ' + sFilename);
  Result := FileDateToDateTime(iDosTime);
end;
 
procedure ChangeModifiedDate(const aFilename: string; aDateTime: TDateTime);
begin
  FileSetDate(aFileName, DateTimeToFileDate(aDateTime));
end;