您的位置:程序门 -> delphi -> vcl组件开发及应用



如何查找文件夹1下子文件夹的个数?


[收藏此页] [打印本页]选择字色:背景色:字体:[][][]


如何查找文件夹1下子文件夹的个数?[已结贴,结贴人:burth]
发表于:2007-04-18 23:16:13 楼主
在文件夹1下游很多子文件夹,分别为文件夹2,文件夹3等,在文件夹2下又有子文件夹4,文件夹5等,我最终想统计最低成的文件夹个数。
例如:
      文件夹1   下有   文件夹2,文件夹3。文件夹2下没有文件夹,文件夹3下有文件夹4,文件夹5,最终统计个数为3,即被统计的文件夹有。文件夹2,文件夹4,文件夹5。
发表于:2007-04-19 08:44:291楼 得分:10
用递归遍历所有的子文件夹,统计数量
发表于:2007-04-19 08:51:182楼 得分:10
用findfirst,findnext
发表于:2007-04-19 09:10:013楼 得分:10
恩   用findfirst,findnext,findclose来做

然后定义个tsearchrec的变量,至于怎么用这个类型的变量

在delphi里f1一下就可以找到他的属性
发表于:2007-04-22 00:34:094楼 得分:0
请写一段代码好么?我是初学者,不太懂,最好是在代码后面加上注释,谢谢.
发表于:2007-04-22 00:56:295楼 得分:0
看帮助吧
发表于:2007-04-22 17:31:076楼 得分:20
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;


快速检索

最新资讯
热门点击