Link to home
Start Free TrialLog in
Avatar of Tulip
Tulip

asked on

How to change a file's date/time ?

I want to change the date/time of a file and tried it with the following code.
At run-time the error "invalid variant type conversion" occurs.
It has to do with the conversion of the filename-string, but I have no idea
what to change. Can anyone help me ?

Thanks in advance,
Tulip

var handle : THandle;
    ft : TFileTime;
    dt : TDateTime;
    st : TSystemTime;
    filename : String;
begin
  filename := 'C:\temp\test.txt';
  dt := EncodeDate(1999, 1, 1);
  dt := dt + EncodeTime(17, 30, 0, 0);
  DateTimeToSystemTime(dt, st);
  SystemTimeToFileTime(st, ft);
  handle := CreateFile(PChar(filename), GENERIC_WRITE, FILE_SHARE_READ, nil, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
  SetFileTime(handle, nil, nil, @ft);
  CloseHandle(handle);
end;
ASKER CERTIFIED SOLUTION
Avatar of XAN
XAN

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial