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://img2024.cnblogs.com/blog/35695/202408/35695-20240826070647288-243310440.jpg)