如何知道某个目录下的下级子目录数目
如 D:\MASTERJAMES\下有
 D:\MASTERJAMES\MM
 D:\MASTERJAMES\MM2
则数目为2,最好不要搜索所有的子目录

解决方案 »

  1.   

    D:\MASTERJAMES\MM\GF1
    D:\MASTERJAMES\MM\GF2
    D:\MASTERJAMES\MM\GF3
    D:\MASTERJAMES\MM\则为3
      

  2.   

    function FindAllFile(DPath:string;FindType:integer):integer;//目录名字和文件列表还是目录列表
    var
      Found:integer; SearchRec:TSearchRec; //,Attr
      DirList,FileList:TStrings;   //目录名列表和文件名列表
      Procedure ProcessSearchRec(SRec:TSearchRec);
      begin
        if (SRec.Name<>'.') and (SRec.Name<>'..') and (SRec.Attr=16) then
          DirList.Add(SRec.Name);
        if (SRec.Name<>'.') and (SRec.Name<>'..') and (SRec.Attr<>16) then   //Action.ini列表
          FileList.Add(SRec.Name);
      end;
    begin
      DirList:=TStringList.Create;
      FileList:=TStringList.Create;  Found := FindFirst(DPath+'\*.*', faAnyFile, SearchRec);
      while Found = 0 do
        begin
          ProcessSearchRec(SearchRec);
          Found := FindNext(SearchRec);
        end;
      FindClose(SearchRec);
      if FindType=0 then
        Result:=DirList.Count;
      if FindType=1 then
        Result:=FileList.Count;
      DirList.Free;
      FileList.Free;
    end;以前自己用的函数,调用方式 count:=FindAllFile('D:\MASTERJAMES\MM',0);
      

  3.   

    FindFirst;//faDirectory
    FindNext;
    FindClose;