设置文件日期

procedure SetFileDateTime(const Tf: string; now1: TDateTime);
var
  Dt1, Dt2: Integer;
  Fs: TFileStream;
  Fct, Flt: TFileTime;
begin
  Dt1 := DateTimeToFileDate(now1);
  Dt2 := Dt1;
  try
    FS := TFileStream.Create(Tf, fmOpenReadWrite);
    try
      if DosDateTimeToFileTime(LongRec(DT1).Hi, LongRec(DT1).Lo, Fct) and
        LocalFileTimeToFileTime(Fct, Fct) and
        DosDateTimeToFileTime(LongRec(DT2).Hi, LongRec(DT2).Lo, Flt) and
        LocalFileTimeToFileTime(Flt, Flt) then
        SetFileTime(FS.Handle, @Fct, @Flt, @Flt); {设置文件时间属性 }
    finally
      FS.Free;
    end;
  except
    MessageDlg('日期修改操作失败!', mtError, [mbOk], 0); { 因为目标文件正被使用等原因而致失败}
  end;
end;

原文地址:https://www.cnblogs.com/djcsch2001/p/1831244.html