Files Delphi

Title: Get the number of files in a directory with recurtion
Question: How to retrieve the number of files in a directory recursevely
Answer:
function CountFiles(const ADirectory: String): Integer;
var
Rec : TSearchRec;
sts : Integer ;
begin
Result := 0;
sts := FindFirst(ADirectory + '\*.*', faAnyFile, Rec);
if sts = 0 then
begin
repeat
if ((Rec.Attr and faDirectory) faDirectory) then
Inc(Result)
else if (Rec.Name '.') and (Rec.Name '..') then
Result := Result + CountFiles(ADirectory + '\'+ Rec.Name);
until FindNext(Rec) 0;
SysUtils.FindClose(Rec);
end;
end;