procedure TMainForm.findfiles(Apath:string);
var
  FSearchrec,DSearchrec:TSearchRec;
  FindResult:integer;
  function getdirname(dirname:string):string;
  begin
    if dirname[length(dirname)]<>'\' then
     result:=dirname+'\'
    else
     result:=dirname;
  end;
  function IsDirNotation(Adirname:string):bool;
  begin
    result:=(adirname='.') or (adirname='..');
  end;
begin
  apath:=getdirname(apath);
  FindResult:=findfirst(Apath+'*.pas',faAnyFile+faHidden+faSysFile+faReadOnly,FSearchRec);
  try
    while findresult=0 do
    begin
      listbox1.Items.Add(lowercase(Apath+FSearchRec.Name));
      findresult:=findnext(FSearchRec);
    end;
    findresult:=findfirst(apath+'*.*',faDirectory,DSearchRec);
    while findresult=0 do
    begin
      if ((DSearchRec.Attr and faDirectory)= faDirectory)
        and not IsDirNotation(DSearchRec.Name) then
        findfiles(apath+DSearchRec.Name);
      findresult:=findnext(DSearchRec);
    end;
  finally
    findclose(FSearchRec);
  end;
end;

解决方案 »

  1.   

    肯定是要用FindFirst/FindNext了,具体实现也就是二楼的了。
      

  2.   

    要不要原码。
    发信给我,[email protected]
    最近有效。
      

  3.   

    procedure SearchFile(const Path:string);//path中要有"\"
    var
      SR:TSearchRec;
      found:integer;
    begin
      found:=FindFirst(path+'*.*',faAnyFile,SR);
      while found=0 do
      begin
        if (SR.Attr=faDirectory) and (SR.Name<>'..') and (SR.Name<>'.') then
          SeardhFile(Path+SR.Name+'\');
        ListBox.items.Add(SR.Name);
        found:=FindNext(SR);
      end;
      FindClose(SR);
    end;