Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what i can set create/last modified/last access of a file?

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.

like image 976
Marcello Impastato Avatar asked Dec 02 '22 01:12

Marcello Impastato


2 Answers

In unit IOUtils.pas you can find the corresponding methods in the records TFile and TDirectory: SetCreationTime, SetLastAccesstime, SetLastWriteTime accompanied by their UTC sibblings.

like image 120
Uwe Raabe Avatar answered Dec 22 '22 23:12

Uwe Raabe


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));
like image 28
RRUZ Avatar answered Dec 23 '22 00:12

RRUZ