Witam, czy widzicie moze jakies sposoby optymalizacji, czy skrocenia tych funckji, ale tak aby nie platac zwyklego uzytkownika w dodatkowe pojecia? Moze da sie obie funkcje zamienic w jedna?
function HasFiles(const Path, Mask: string; Recursion: Boolean = True; EndAt: Integer = 1; _Count: Integer = 0): Integer;
var
SRec: TSearchRec;
sPath, sSearch: string;
res: Integer;
begin
Result := _Count;
sPath := ITB(Path);
sSearch := sPath + Mask;
if FindFirst(sSearch, faAnyFile - faDirectory, SRec) = 0 then
repeat
Inc(Result);
if Result = EndAt then
Exit;
until FindNext(SRec) <> 0;
FindClose(SRec);
if Recursion then
begin
res := FindFirst(sSearch, faArchive + faHidden + faDirectory + faReadOnly, SRec);
while res = 0 do
begin
if (SRec.Attr and faDirectory <> 0) and (SRec.Name <> '.') and (SRec.Name <> '..') then
begin
Result := HasFiles(sPath + srec.Name, Mask, Recursion, EndAt, Result);
if Result = EndAt then
Exit;
end;
res := FindNext(SRec);
end;
FindClose(SRec);
end;
end;
function HasDirs(const Path, Mask: string; Recursion: Boolean = True; EndAt: Integer = 1; _Count: Integer = 0): Integer;
var
SRec: TSearchRec;
sPath, sSearch: string;
res: Integer;
begin
Result := _Count;
sPath := ITB(Path);
sSearch := sPath + Mask;
if FindFirst(sSearch, faArchive + faHidden + faDirectory + faReadOnly, SRec) = 0 then
repeat
if (SRec.Attr and faDirectory <> 0) and (SRec.Name <> '.') and (SRec.Name <> '..') then
begin
Inc(Result);
if Result = EndAt then
Exit;
end;
until FindNext(SRec) <> 0;
FindClose(SRec);
if Recursion then
begin
res := FindFirst(sSearch, faArchive + faHidden + faDirectory + faReadOnly, SRec);
while res = 0 do
begin
if (SRec.Attr and faDirectory <> 0) and (SRec.Name <> '.') and (SRec.Name <> '..') then
begin
Result := HasDirs(sPath + srec.Name, Mask, Recursion, EndAt, Result);
if Result = EndAt then
Exit;
end;
res := FindNext(SRec);
end;
FindClose(SRec);
end;
end;
P.S. Wprowadzilem male poprawki bo byl blad.