Author: Den Bedard
How do I change the date & time of a file specified as a string?
Answer:
Often A file's time is set to represent a version number. For example the datetime
may be January 27, 2000 1:03:00AM to represent version 1 patch 3.
This unit presents a procedure which takes two parameters, A file path/name
specified as a string and a DateTime.
The specified file's date & time will be changed to match the DateTime specified.
1 unit Fileutil;
2 3 interface4 uses System, SysUtils;
5 6 {To Change the Date/Time of a file}7 procedure TouchFile(FileName: string; Date: TDateTime);
8 9 implementation10 11 procedure TouchFile(FileName: string; Date: TDateTime);
12 var13 TheFile: file;
14 begin15 AssignFile(TheFile, FileName);
16 Reset(TheFile);
17 FileSetDate(TFileRec(TheFile).Handle,
18 DateTimeToFileDate(Date));
19 Close(TheFile);
20 end;
21 22 end.