如何查找文件夹1下子文件夹的个数?
在文件夹1下游很多子文件夹,分别为文件夹2,文件夹3等,在文件夹2下又有子文件夹4,文件夹5等,我最终想统计最低成的文件夹个数。
例如:
文件夹1 下有 文件夹2,文件夹3。文件夹2下没有文件夹,文件夹3下有文件夹4,文件夹5,最终统计个数为3,即被统计的文件夹有。文件夹2,文件夹4,文件夹5。
[解决办法]
用递归遍历所有的子文件夹,统计数量
[解决办法]
用FindFirst,FindNext
[解决办法]
恩 用FindFirst,FindNext,FindClose来做
然后定义个TSearchRec的变量,至于怎么用这个类型的变量
在DELPHI里F1一下就可以找到他的属性
[解决办法]
procedure TForm1.FindDir(s:String);
var
temPath:String;
sr:TSearchRec;
begin
temPath:=s+ '\*.* ';
if FindFirst(temPath,faAnyFile,sr)=0 then
repeat
if (sr.Name= '. ') or (sr.Name= '.. ') then continue
else if (sr.Attr and faDirectory)=sr.Attr then
begin
memo1.Lines.Add(sr.name);
FindDir(s+ '\ '+sr.Name);
end;
until FindNext(sr) <> 0 ;
FindClose(sr);
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
FindDir( 'c: ');
end;