System.SysUtils.FileAge

From RAD Studio API Documentation
Jump to: navigation, search

Delphi

function FileAge(const FileName: string): LongInt; overload;
function FileAge(const FileName: string; out FileDateTime: TDateTime; FollowLink: Boolean = True): Boolean;

C++

extern DELPHI_PACKAGE int __fastcall FileAge _DEPRECATED_ATTRIBUTE0 (const System::UnicodeString FileName)/* overload */;

Properties

Type Visibility Source Unit Parent
function public
System.SysUtils.pas
System.SysUtils.hpp
System.SysUtils System.SysUtils

Description

Returns the OS time stamp of a file.

Call FileAge to obtain the OS time stamp of the file specified by the FileName parameter.

The first overload returns an integer that represents the OS time stamp of the file. The result can be later converted to a TDateTime using the FileDateToDateTime function.

Note: The first overloaded version of FileAge is deprecated. Use the second version of FileAge instead.

The second overload is preferred, and returns the time stamp of FileName in the FileDateTime output parameter. For example, here is the preferred C++ syntax:

extern DELPHI_PACKAGE bool __fastcall FileAge(const System::UnicodeString FileName, /* out */ System::TDateTime &FileDateTime, bool FollowLink = true)/* overload */;

If the FileName parameter is a symbolic link and the FollowLink parameter is set to True, the method is performed on the target file. If the first condition is True, but the FollowLink parameter is set to False, the time stamp of the symbolic link is returned. The return value is True if the operation succeeded, or False otherwise.

Example

Delphi:

uses
  System.SysUtils;
var
  timeDate : TDateTime;
begin
  FileAge('C:\Users\User\Desktop\aFile.xml', timeDate);
  writeln(DateTimeToStr(timeDate));
end.

C++:

#include <System.SysUtils.hpp>
#include <stdio.h>
 
int main()
{
  TDateTime *timeDate = new TDateTime();
  UnicodeString aFile = "C:\\Users\\User\\Desktop\\aFile.xml";
  FileAge(aFile, *timeDate, true);
  printf("%ls", DateTimeToStr(*timeDate));
  return 0;
}

See Also

Code Examples