同上

解决方案 »

  1.   

    你看看这个里面有公用函数可以做得到
    http://expert.csdn.net/Expert/topic/1656/1656068.xml?temp=.3735315
      

  2.   

    unit unit1;interfaceuses
      Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
      Db, DBTables, StdCtrls, DBCtrls, Mask, ExtCtrls;type
      TForm1 = class(TForm)
        Button1: TButton;
        Memo1: TMemo;
        Edit1: TEdit;
        procedure Button1Click(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;var
      Form1: TForm1;
      countd,countf:integer;
    implementation{$R *.DFM}procedure search(dir:string);
    var
      targetpath:string;{目标路径名}
      sr:TsearchRec;begin
      {第一阶段:找出初始dir目录下的所有文件,
      其中dir变量值由edit1的Text属性确定}  targetpath:=extractfilepath(dir);{分解出目标路径名}
      if findfirst(dir,faanyfile,sr)=0 then
      repeat
       if((sr.name<>'.')and(sr.name<>'..'){排除父目录和本目录两个假文件}
       and((filegetattr(targetpath+sr.name)and fadirectory)<>fadirectory)){只取文件}
       then
         begin
         form1.memo1.Lines.Add(targetpath+sr.name);{在memo中添加找到的文件}
         countf:=countf+1;
         end
      until findnext(sr)<>0;  if findfirst(dir,faanyfile,sr)=0 then
      repeat
       if((sr.name<>'.')and(sr.name<>'..')){排除父目录和本目录两个假文件}
       and((filegetattr(targetpath+sr.name)and fadirectory)=fadirectory){排除文件}
       then
        begin
         search(targetpath+sr.name+'\*.*');{递归调用}
         form1.memo1.Lines.Add(targetpath+sr.name);     countd:=countd+1;
        end
      until findnext(sr)<>0;end;procedure TForm1.Button1Click(Sender: TObject);
    begin
      countf:=0;
      countd:=0;
      memo1.Clear;{清除数据表memo字段内容}
      search(Edit1.Text);{调用Search()函数}
      MessageDlg('文件搜索完毕!',mtInformation,[mbOk],0);{结束提示}
      showmessage('目录:'+inttostr(countd)+' 文件:'+inttostr(countf))
    end;end.
      

  3.   

    在edit1中输入时加上、\*.*,自己把程序改一下也行