|
You may want to get the age of a file eg. the date when the file was created.
To do this you can use the FileAge function and then use the FileDateToDateTime function to convert the DOS date-time value into a TDateTime format.
FILEAGE
=======
Declaration
-----------
function FileAge(const FileName: string): Integer;
Description
-----------
The return value can be converted to a TDateTime value using the FileDateToDateTime
function.
The return value is -1 if the file does not exist.
FILEDATETODATETIME
==================
Declaration
-----------
function FileDateToDateTime(FileDate: Integer): TDateTime;
Description
-----------
The FileAge, FileGetDate, and FileSetDate routines operate on DOS date-time
values, and the Time field of a TSearchRec used by the FindFirst and FindNext
functions contains a DOS date-time value.
Example
=======
var
Age: Integer;
begin
If (OpenDialog.Execute) then
begin
Age := FileAge(OpenDialog.Filename);
Label1.Caption := FormatDateTime('dd
mmmm yyyy', FileDateToDateTime(Age));
end;
end;
In this example a open-dialog box allows you to select any file and
return the age of that file into a label, using the date format "dd mmmm
yyyy" (eg. 20 August 2000, etc).
NOTE: Remember to add the SysUtils unit to your application's uses-clause.