SysUtilsFileGetSetDate (Object Pascal)

From Appmethod Code Examples
Jump to: navigation, search

Description

This example illustrates the FileGetDate and FileSetDate functions from the SysUtils unit. In the case of a file named "test.txt", first get the date and time from that file, and then change it.

Code

var
  LH: THandle;
  LFDate: Integer;

begin
  { Open a file. }
  LH := FileOpen('test.txt', fmOpenRead);
  { Get the date from the file. }
  LFDate := FileGetDate(LH);
  { Close the file. }
  FileClose(LH);

  { Increment the old date by one hour, then apply the new date. }
  FileSetDate('test.txt',
    DateTimeToFileDate(
      IncHour(FileDateToDateTime(LFDate), 1)));
end.

Uses