[Lazarus] Getting the last modified date of a directory

Marco van de Voort marcov at stack.nl
Sat Dec 27 22:37:20 CET 2014


On Sat, Oct 25, 2014 at 06:19:07PM +0100, Richard Mace wrote:
> I can see that we have a "FileAge" function and also a "FileGetDate"
> however, I was wondering what the best way of getting the last modified
> date of a folder? Effectively, the last time that a file was
> created/changed within a folder?

On Windows you can access finddata, I did this to get the creation time, but
the record has multiple fields:

{$mode delphi}
uses sysutils,windows;

function GetFileInformation(const FileName: string; out FileInfo:
TSearchRec): Boolean;
begin
  Result := FindFirst(FileName, faAnyFile, FileInfo) = 0;
  if Result then
    SysUtils.FindClose(FileInfo);
end;

function GetFileInformation2(const FileName: string): TSearchRec;
begin
  if not GetFileInformation(FileName, Result) then
    RaiseLastOSError;
end;

function GetFileCreation(const FileName: string): TFileTime;
begin
   Result := GetFileInformation2(FileName).FindData.ftCreationTime;
end;





More information about the Lazarus mailing list