Files Delphi

function SetFileDateTime(FileName: string; NewDateTime: TDateTime): Boolean;
var
FileHandle: Integer;
FileTime: TFileTime;
LFT: TFileTime;
LST: TSystemTime;
begin
Result := False;
try
DecodeDate(NewDateTime, LST.wYear, LST.wMonth, LST.wDay);
DecodeTime(NewDateTime, LST.wHour, LST.wMinute, LST.wSecond, LST.wMilliSeconds);
if SystemTimeToFileTime(LST, LFT) then
begin
if LocalFileTimeToFileTime(LFT, FileTime) then
begin
FileHandle := FileOpen(FileName, fmOpenReadWrite or
fmShareExclusive);
if SetFileTime(FileHandle, nil, nil, @FileTime) then
Result := True;
end;
end;
finally
FileClose(FileHandle);
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
if OpenDialog1.Execute then
if SetFileDateTime(OpenDialog1.FileName, now) then
ShowMessage('Date set to now !');
end;
--------------------------------------
Function SetFileDate(
Const FileName : String;
Const FileDate : TDateTime): Boolean;
Var
FileHandle : THandle;
FileSetDateResult : Integer;
Begin
FileHandle := 0;
Result := False;
Try
Try
FileHandle := FileOpen(FileName, fmOpenWrite OR fmShareDenyNone);
If FileHandle > 0 Then
Begin
FileSetDateResult :=
FileSetDate(
FileHandle,
DateTimeToFileDate(FileDate));
Result := (FileSetDateResult = 0);
End;
Except
Result := False;
End;
Finally
FileClose (FileHandle);
End;
End;