如何获取一个文件夹下面的所有子文件名,并将它子文件名一一列在一个窗口上 ?请各位大虾帮帮忙!

解决方案 »

  1.   

    下面是我的一个函数,你自己改改//找指定目录下的所有符合条件的文件名
    function SearchFile(const mainpath:string;filename:string;var foundresult:TStrings):Boolean;
    var
      i:integer;
      Found:Boolean;
      subdir1:TStrings;
      searchRec:TsearchRec;
      SR : TSearchRec;
    begin
      found:=false;
      if Trim(filename)<>'' then
      begin
        if FindFirst(mainpath+filename,faDirectory,sr)=0 then
        repeat
        begin
          found:=true;
          foundresult.Add(mainpath+SR.Name);
        end
        until FindNext(sr)<>0;
        FindClose(SR);    if FindFirst(mainpath+'*.*', faDirectory, SearchRec)=0 then
        begin
          while FindNext(SearchRec) = 0 do
          begin
            if SearchRec.Name<>'..' then
            begin
              found := SearchFile(mainpath+SearchRec.Name+'\',Filename,foundresult)or found;
            end;
          end;
        end;
        FindClose(SearchRec);
      end;
      result:=Found;
    end;
      

  2.   

    可以包含子文件夹procedure TForm1.FindFiles(Apath:string);
    var
        FSearchRec,DSearchRec:TSearchRec;
        FindResult:integer;
    begin
        if apath[length(apath)]<>'\' then apath:=apath+'\';
        FindResult:=FindFirst(Apath+'*.*',faAnyFile+faHidden+faSysFile+faReadOnly,FSearchRec);
        try
           while FindResult=0 do
           begin
               ListBox1.Items.Add(Apath+FSearchRec.Name);
               FindResult:=FindNext(FSearchRec);
           end;
           FindResult:=FindFirst(Apath+'*.*',faDirectory,DSearchRec );
           while FindResult =0 do
           begin
               if ((DSearchRec.Attr and fadirectory)=fadirectory) and (leftstr(DSearchRec.Name,1)<>'.') then
                   FindFiles(Apath+DSearchRec.Name);
               FindResult:=FindNext(DSearchRec );
           end;
        finally
           FindClose(FSearchRec);
        end;
    end;procedure TForm1.Button1Click(Sender: TObject);
    begin
        FindFiles('D:\test\');
    end;
      

  3.   

    估计有这样的控件~~~~********************************************************************
    *TryMyBestToKnowSomethingAboutEverythingAndEverythingAboutSomething! 
    ********************************************************************
      

  4.   

    推荐使用Windows.FindFirstFile的方法,能支持2GB以上文件的Size
    Delphi自己的FindFirst就不支持的_____________________
    http://lysoft.7u7.net
      

  5.   

    BusinessSkinForm里有个bsSkinFileListBox有这样的功能,Mask属性可以选择文件夹。