Arquivos - ler e modificar data e hora do arquivo

Top  Previous  Next

var

  HFile : Integer;

  D2    : TDateTime;

begin

  if NOT FileExists('C:\Autoexec.bat') then

  begin

    ShowMessage('O arquivo não foi encontrado');

    Exit;

  end;

 

  HFile := FileOpen('C:\Autoexec.bat', fmOpenWrite);

  If HFile > 0 then

  begin

    D2 := FileDateToDateTime(FileGetDate(HFile));

    Caption := DateToStr(D2) + ' - ' + TimeToStr(D2);

 

  FileSetDate(HFile, DateTimeToFileDate(Now));

  FileClose(HFile);

end;