请问各位,如何可以得到某一路径下的所有子目录名称?

解决方案 »

  1.   

    简单的调用dos命令 dir /ad
      

  2.   

    GetCurrentDir()这个函数就是获取目录名的。
      

  3.   

    {
    参数:
      DirName   查找的目录
      FileList  找到的文件, 需要调用前创建
      IncSubDir 是否包括子目录,True包括,否则不包括。默认包括子目录。
    }
    procedure FindFile(DirName:string;var FileList:TStrings; IncSubDir:boolean=True);
    var DS:TSearchRec;
      i,p:integer;
      Path:string;
      DirList:TStrings;
    begin
      i := 0;
      DirName :=ExcludeTrailingPathDelimiter(DirName);
      DirList := TStringList.Create;
      DirList.Add(DirName);
      while i < DirList.Count do
      begin
        Path := DirList.Strings[i] + '\';
        if FindFirst(Path + '*.*', faAnyFile, Ds) = 0 then
          repeat
            if (Ds.Attr and faDirectory) = 0 then
              FileList.Add(Path + Ds.Name)
            else
              if IncSubDir and (Ds.Name[1] <> '.')  then
                DirList.Add(Path + Ds.Name);
          until FindNext(Ds) <> 0;
        Inc(i);
        //显示进度
        p := i * 100 div DirList.Count;
        if p > Form1.ProgressBar1.Position then
          Form1.ProgressBar1.Position := p;
        FindClose(Ds);
      end;
      DirList.Free;
    end;
    procedure TForm1.Button1Click(Sender: TObject);
    var FileList:TStrings;
    begin
      FileList := TStringList.Create;
      FindFile('c:', FileList);   //查找C盘所有文件
      FileList.Free;
    end;
      

  4.   

    用FindFirst这个函数,参数faDirectory ,用法找HELP吧