Author: Jonas Bilinkevicius
How to get the number of files in a folder
Answer:
1 uses2 Windows, { ... }3 4 function FileCount(const aFolder: string): Integer;
5 var6 H: THandle;
7 Data: TWin32FindData;
8 begin9 Result := 0;
10 H := FindFirstFile(PCHAR(aFolder + '*.*'), Data);
11 if H <> INVALID_HANDLE_VALUE then12 repeat13 Inc(Result, Ord(Data.dwFileAttributes and FILE_ATTRIBUTE_DIRECTORY = 0));
14 until15 not FindNextFile(H, Data);
16 Windows.FindClose(H);
17 end;