in: How to get create/last modified dates of a file in Delphi? i have found as get create/last modified/last access date/time of a un file, but for set this value in a file, what i can to do? Thanks very much.
In unit IOUtils.pas
you can find the corresponding methods in the records TFile
and TDirectory
: SetCreationTime
, SetLastAccesstime
, SetLastWriteTime
accompanied by their UTC sibblings.
Try the SysUtils.FileSetDate
function from the SysUtils unit, which internally call the SetFileTime
WinApi function.
this funcion has two versions
function FileSetDate(const FileName: string; Age: Integer): Integer;
function FileSetDate(Handle: THandle; Age: Integer): Integer;
The Age parameter is the Time to set. You must use the DateTimeToFileDate
to convert a TDateTime Value to the Windows OS time stamp.
Like this
FileSetDate(FileName, DateTimeToFileDate(Now));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With