procedure FindFiles(Path: String);
var sr: TSearchRec;
    ret: Integer;
begin
  ret := FindFirst(Path + '\*.*',faAnyFile,sr);
  while(ret=0) do
  begin
    if Pos('.',sr.Name) = 0 then
      FindFiles(Path + '\' + sr.name);    Form1.Memo1.Lines.Add(sr.name);
    ret := findnext(sr);
  end;
  FindClose(sr);
end;procedure TForm1.Button1Click(Sender: TObject);
begin
  FindFiles('C:\');end;

解决方案 »

  1.   

    to  Borlandor(五角▲大民):
    有'.'的不一定不是目录,没有'.'的不一定就是目录.
    var
      sr: TSearchRec;
      FindRet: Integer;
    begin
    FindRet := FindFirst('C:\*.*',faDirectory,sr);
    while FindRet = 0 do
    begin
      if (sr.Attr and faDirectory) <> 0 then
        ListBox1.Items.Add(sr.Name);
      FindRet := FindNext(sr);
    end;
    FindClose(sr);
    end;
      

  2.   

    拿楼上的改一改
    procedure FindFiles(Path: String;findall:boolean);
    var sr: TSearchRec;
        ret: Integer;
    begin
      ret := FindFirst(Path + '\*.*',faAnyFile,sr);
      while(ret=0) do
      begin
        if (sr.Name <> '.') and (sr.Name <> '..') and ((SR.Attr and faDirectory) > 0) then
        begin
             if findall then FindFiles(Path + '\' + sr.name,findall);
             Form1.Memo1.Lines.Add(sr.name);
        end;
        ret := findnext(sr);
      end;
      FindClose(sr);
    end;procedure TForm1.Button1Click(Sender: TObject);
    begin
      FindFiles('D:\',false);//查找d:根目录下所有目录
    end;procedure TForm1.Button2Click(Sender: TObject);
    begin
      FindFiles('D:\',true);//查找d:根目录下所有目录(包含子目录)
    end;
      

  3.   

    用DirectoryListBox控件procedure TForm1.Button3Click(Sender: TObject);
    var i: integer;
    begin
      with DirectoryListBox1 do
      begin
        Directory :='c:\';
        for i:=1 to Items.count-1 do
          ListBox1.Items.Add(GetItemPath(i));
      end;
    end;
      

  4.   

    procedure FindFiles(Path: String;findall:boolean);
    var sr: TSearchRec;
        ret: Integer;
    begin
      ret := FindFirst(Path + '\*.*',faAnyFile,sr);
      while(ret=0) do
      begin
        if (sr.Name <> '.') and (sr.Name <> '..') and ((SR.Attr and faDirectory) > 0) then
        begin
             if findall then FindFiles(Path + '\' + sr.name,findall);
             Form1.Memo1.Lines.Add(sr.name);
        end;
        ret := findnext(sr);
      end;
      FindClose(sr);
    end;procedure TForm1.Button1Click(Sender: TObject);
    begin
      FindFiles('c:\',false);//查找d:根目录下所有目录
    end;
      

  5.   

    楼上已经回答了我就不回答了!哈哈
    ================================================================
    一颗红心向前看,为了革命两茫然,不好意思才囊尽,只能说上一点点。
    ★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆
    ★    我踢  我踢   我踢  我踢  我踢  我踢  我踢  我踢  我踢   ★
    ★    你UP  你UP   你UP  你UP  你UP  你UP  你UP  你UP  你UP   ★
    ★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆
    ================================================================
      

  6.   

    哈哈!
    午休期间竟然这么热闹!>>有'.'的不一定不是目录,没有'.'的不一定就是目录.对的,自己调整吧!