Mega Code Archive

 
Categories / Delphi / Files
 

Changing Date and time stamp of a file

Title: Changing Date and time stamp of a file Question: How can I change the Date and time stamp of a file ? Answer: Once an file is modified and saved, the date and time stamp of the file gets the value from the machine's date and time. In order to change the date and time stamp of the file, we have to set the machine's date and time to a new value and save the file once again. Then we have to reset the machine's date and time to the orginal date and time. This piece of code changes the date and time stamp of any file to the any date and time value. procedure ChangefileStamp(filename : TFileName; newtime: TDateTime); var vhnd : Integer; begin vhnd := FileOpen( filename, fmOpenReadWrite ); FileSetDate( vhnd, Datetimetofiledate(newtime) ); FileClose(vhnd); end;