Author: William Gerbert
Date and time of creation/modification of a file
Answer:
The function FileAge() returns the date/time stamp of a file. The returned value is
an integer number; it has to be converted to Delphi's TDateTime format (a floating
point number) before you can use it. You can use the following code to test the
functions involved:
1 procedure TForm1.Button1Click(Sender: TObject);
2 var3 File_Name: string;
4 DateTimeStamp: integer;
5 Date_Time: TDateTime;
6 begin7 File_Name := 'c:\mydocuments\test.doc';
8 DateTimeStamp := FileAge(File_Name);
9 // FileAge returns -1 if file not found10 if DateTimeStamp < 0 then11 ShowMessage('File not found')
12 else13 begin14 // Convert to TDateTime format15 Date_Time := FileDateToDateTime(DateTimeStamp);
16 Label1.Caption := DateToStr(Date_Time);
17 Label2.Caption := TimeToStr(Date_Time);
18 end;
19 end;