本人采用RzShelltree能够获得指定的文件夹路径,然后采用Delphi 7 组建编程参考手册上的递归搜索文件夹中的文件代码,可是代码运行没问题,但是 FileListBox 为空白,请高手指点,多谢。代码如下procedure TForm7.FindFiles(APath : string);
var
    FindResult:integer;
    FFileName : string;
    FSearchRec, DSearchRec: TSearchRec;
    Function IsDirNotation(ADirName: string):Boolean;
    begin
       Result:=(ADirName='.') or (ADirName='..');
    end;
begin
    if APath<>'' then
    begin
       RzFileListBox1.Items.BeginUpdate;
       RzFileListBox1.Items.Clear ;
       FFileName:='*.*';
       Directory:= APath + '';
       if Directory[Length(Directory)]<>'\' then
          Directory:=Directory+'\';       FindResult:=FindFirst(Directory+FFileName, faAnyFile, FSearchRec);
       try
          while FindResult=0 do
          begin
             RzFileListBox1.Items.Add(LowerCase(Directory+FSearchRec.Name));
             FindResult:=FindNext(FSearchRec);
          end;
          FindResult:=FindFirst(Directory+FFileName, faDirectory, DSearchRec);
          while FindResult=0 do
          begin
             if ((DSearchRec.Attr and faDirectory )=faDirectory) and not
                  IsDirNotation(DSearchRec.Name) then
                FindFiles(Directory+DSearchRec.Name);
             FindResult:=FindNext(DSearchRec);
          end;
       finally
          FindClose(FSearchRec);
       end;
    end;
end;
procedure TForm7.RzShellTree1Change(Sender: TObject; Node: TTreeNode);
begin
    pathname:=RzShellTree1.SelectedPathName;
    try
       FindFiles(pathname);
    finally
       Screen.Cursor:=crDefault;
    end;
end;

解决方案 »

  1.   

    怎么会处理得这么麻烦,FileListBox有个Directory属性啊,把目录指定给他,自动就把目录下的文件列出来了
    procedure TForm1.ShellTreeView1Change(Sender: TObject; Node: TTreeNode);
    begin
      if not DirectoryExists(ShellTreeView1.SelectedFolder.PathName) then
      begin
        Exit;
      end;
      FileListBox1.Directory := ShellTreeView1.SelectedFolder.PathName;
    end;
      

  2.   

    自己调试吧,断点在RzFileListBox1.Items.Add处,看看是否执行到此了
      

  3.   

    十分感谢楼上两位高手指点,我还想补充下,‘xutaiqing’的方法能够显示出指定文件夹中的全部文件,我若只想让其显示'.xls; .xlsx; .bmp; .doc'文件需要怎么修改代码呢?谢谢了
      

  4.   

    查找的时候加上判断,如
    while FindResult=0 do
    begin
      if pos('.xls',lowercase(FSearchRec.Name))>0 then
         RzFileListBox1.Items.Add(LowerCase(Directory+FSearchRec.Name));
      FindResult:=FindNext(FSearchRec);
    end;
      

  5.   


    你用ShellListView控件吧,直接关联ShellTreeView,在ShellListView的AddFolder事件中对AFolder.PathName进行判断,如果后缀是你要的,就CanAdd := True
      

  6.   

    楼上这位兄弟,我采用的是Rz控件 中的RzShellTree 和 RzFileListBox,RzShellTree中没有你所说的AddFolder事件,只有AddItem 事件, 怎么才能进行文件过滤呢,谢谢了
      

  7.   

    FileListBox有个Mask属性,可以设置文件的扩展名,不过貌似只能设置一个扩展名。