获得指定文件夹下的子目录数

时间:2020-12-29 12:33:10

function GetDirCount(ThePath:string):integer

function IsValidDir(SearchRec:TSearchRec):Boolean;

begin

if (SearchRec.Attr=16) and (SearchRec.Name<>'.') and (SearchRec.Name<>'.'.) then

Result :=True

else

Result :=False;

end;

var

num:integer;

sr:TSearchRec;

begin

num :=0;

if (FindFirst(ThePath,faDirectory,sr)=0) then

begin

if IsValidDir(sr) then

num :=num+1;

while (FindNext(sr)=0) do

begin

if IsValidDir(sr) then

num :=num+1;

end;

end;

result :=num;

end;

end;