Mirror

How to get the number of files in a folder (Views: 101)


Problem/Question/Abstract:

How to get the number of files in a folder

Answer:

uses
  Windows, { ... }

function FileCount(const aFolder: string): Integer;
var
  H: THandle;
  Data: TWin32FindData;
begin
  Result := 0;
  H := FindFirstFile(PCHAR(aFolder + '*.*'), Data);
  if H <> INVALID_HANDLE_VALUE then
    repeat
      Inc(Result, Ord(Data.dwFileAttributes and FILE_ATTRIBUTE_DIRECTORY = 0));
    until
      not FindNextFile(H, Data);
  Windows.FindClose(H);
end;

<< Back to main page