function
SetFileDateTime(FileName:String;NewDate:TDateTime):Boolean;
var i:Integer;
FileTime,FT:TFileTime;
ST:TSystemTime;
begin
Result:=False;
try
DecodeDate(NewDate,LST.wYear,LST.wMonth,LST.wDay);
DecodeTime(NewDate,LST.wHour,LST.wMinute,LST.wSecond,LST.wMilliSeconds);
if SystemTimeToFileTime(ST,FT) then
begin
if LocalFileTimeToFileTime(FT,FileTime)
then
begin
i:=FileOpen(FileName,fmOpenReadWrite or
fmShareExclusive);
if SetFileTime(i,nil,nil,@FileTime)
then
Result:=True;
end;
end;
finally
FileClose(i);
end;
end;
procedure
TForm1.Button1Click(Sender: TObject);
begin
SetFileDateTime('c:\test.txt',Now);
end;
|