如何将某文件夹下的指定扩展名的所有文件显示出来
例如:
将c:\my music里的所有mp3文件的文件名添加到listbox里
请位高手多多指教

解决方案 »

  1.   

    调用这个函数
    procedure TForm1.CreateDirTree(path: string);
    var
      SR:TSearchRec;
      found:integer;
    begin
        found:=FindFirst(path+'*.*',faAnyFile,SR);
        while found=0 do
        begin
            strtmp:=LowerCase(sr.Name);
            if rightstr(strtmp,4)='.txt' then
            begin
                memo1.Lines.Add(path+sr.Name);
                CreateDirTree(path+SR.Name+'\'); 
            end;
          found:=FindNext(SR);
        end;
        FindClose(SR);
    end;
      

  2.   

    procedure TForm1.Button1Click(Sender: TObject);
    begin
        CreateDirTree('c:\my music\');
    end;
    procedure TForm1.CreateDirTree(path: string);
    var
      SR:TSearchRec;
      found:integer;
    begin
        found:=FindFirst(path+'*.*',faAnyFile,SR);
        while found=0 do
        begin
            strtmp:=LowerCase(sr.Name);
            if rightstr(strtmp,4)='.mp3' then
            begin
                Listbox1.Items.Add(path+sr.Name);
                CreateDirTree(path+SR.Name+'\'); 
            end;
          found:=FindNext(SR);
        end;
        FindClose(SR);
    end;
      

  3.   

    上面已经回答出来了,
    就是用FindFirst和FindNext实现
      

  4.   

    function findfile(path:string):string;
    var
      rec:Tsearchrec;
      f:integer;
    begin
      //早上刚写了个子目录查找文件的程序,你就,哈哈
      f:=findfirst(path+'\*.INI',rec);
      while f=0 do
      begin
         if rec.attr=16 then
             findfile(path+'\'+rec.name);//当文件为目录时递归调用
         else
         begin
             ... //为文件时的处理  
         end;
         f:=findnext(rec);
      end;
      findclose(rec);
    end;
      

  5.   

    我是个初学者,,,玩了一下上面的东西,但没弄出来,楼主或者大家能帮忙下吗?能把步骤说详细点吗?或者就说下这个函数的放处以及该如何调用等等。我加了控件,然后把代码copy过去,但有一些错误,第一个是关于这个函数的,由于本人还没学到这些,所以想学习下,请高手指教。谢谢
      

  6.   

    Undeclared identifier: 'CreateDirTree'
    ';' expected but '(' found
    Undeclared identifier: 'path'
    Undeclared identifier: 'rightstr'
    Undeclared identifier: 'Listbox1'
    Missing operator or semicolon
    Undeclared identifier: 'CreateDirTree'
    Undeclared identifier: 'CreateDirTree'
    Could not compile used unit 'Uopen.pas'错误现在还看的不是很明白。其中listbox1我已经加上去了。怎么还有这种错误呐?请指教
      

  7.   

    [Error] Uopen.pas(55): Incompatible types: 'Integer' and 'TSearchRec'
    这个问题怎么解决??
    是 f:=findfirst(path+'\*.INI',rec);这段代码产生的错误....请教.....