Lösung: Code von Joey *DClub* , DelphiLand
Delphi-Quellcode:
procedure CountFiles(FilePath: string);
var
SearchRec: TSearchRec;
Count: Integer;
begin
Count := 0;
if FilePath[Length(FilePath)] <> '\' then FilePath := FilePath + '\';
if FindFirst(FilePath + '*.*', faAnyFile and not faDirectory, SearchRec) = 0 then
begin
Inc(Count);
while FindNext(SearchRec) = 0 do
begin
Inc(Count);
end;
end;
FindClose(SearchRec);
Form1.Label1.Caption := IntToStr(Count);
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
CountFiles('C:\x\');
end;