procedure TForm1.FindFile(ZDGrid:TStringGrid;ZDfile:string;const path:string);
var
   sr:TSearchRec;
   fr,i:Integer;
   SP,ZD:string;
   BG:TStringGrid;
begin
   SP:=path;
   ZD:=ZDfile;
   BG:=ZDGrid;
   if SP[Length(SP)] ='\'  then
//   begin
//   SP[Length(SP)] :='';
//   end;
   SP:=Trim(SP);
   fr:=FindFirst(SP+'\*.'''+ZD+'''',faAnyFile,sr);
   while fr=0 do
  begin
     if (sr.Attr=faDirectory) and (sr.Name<>'.') and (sr.Name<>'..') then
     begin
      BG.Cells[0,BG.RowCount - 3] := SP+'\'+sr.Name;//目录
      BG.RowCount  := BG.RowCount + 1;
      FindFile(ZDGrid,ZD,'\'+sr.Name);  //递归查找下一个目录
     end
     else
    begin
      If (sr.Name<>'.')and(sr.Name<>'..') then //
      begin
        BG.Cells[1,BG.RowCount - 3] := sr.Name;//文件名
        BG.Cells[2,BG.RowCount - 3] := IntToStr(sr.Size);//文件大小
        BG.Cells[3,BG.RowCount - 3] := SP+'\';//文件目录
        for i :=1 to BG.RowCount - 3 do
        begin
          BG.Cells[0,BG.RowCount - 3] :=IntToStr(i);
        end;
        BG.RowCount  := BG.RowCount + 1;
      End;
    end;
    fr := FindNext(sr);
  end;
  FindClose(sr);
end;procedure TForm1.Button1Click(Sender: TObject);
begin
FindFile(StringGrid1;mp3;'F:\歌曲\LIKE');
end;
各位大侠,帮帮忙,看看上面的过程有什么错误!帮忙给改一下!谢谢!急呀。。分少谅解!

解决方案 »

  1.   

    fr:=FindFirst(SP+'\*.'''+ZD+'''',faAnyFile,sr);改为FindFirst(SP+'\*.'+ZD,faAnyFile,sr);FindFile(StringGrid1;mp3;'F:\歌曲\LIKE');改为FindFile(StringGrid1,'mp3','F:\歌曲\LIKE');
      

  2.   

    好人做到底,给你全部代码unit main;interfaceuses
      Windows, SysUtils, Classes, Controls,  Forms,
      StdCtrls, ExtCtrls,ComCtrls, Grids  ;
    type
      TMainForm = class(TForm)
        Button1: TButton;
        StringGrid1: TStringGrid;
        procedure Button1Click(Sender: TObject);  private
        { Private declarations }
        procedure InitStringGrid; //初始化 StringGrid1
      public
        { Public declarations }
        procedure FindAll(const Path: String);
      end;var
      MainForm: TMainForm;
    implementation{$R *.dfm}procedure TMainForm.InitStringGrid; //初始化 StringGrid1
    Var
      I,C:Integer;
      ML,path: string;
    begin
      StringGrid1.ColCount := 3;
      C := StringGrid1.RowCount;
      For I := 0 To C - 1 Do
      Begin
        StringGrid1.Cells[0,I] := '';
        StringGrid1.Cells[1,I] := '';
        StringGrid1.Cells[2,I] := '';
      End;
        StringGrid1.RowCount := 1;
    End;procedure TMainForm.FindAll(const Path: String);
    var
      sr:TSearchRec;
      fr:Integer;
      SP:string;
    begin
      SP := Path;
      If SP[Length(SP)] = '\' Then SP[Length(SP)] := ' ';
      SP := Trim(SP);  fr:=FindFirst(SP+'\*.*',faAnyFile,sr);
      while fr=0 do
      begin
        if (sr.Attr=faDirectory)and(sr.Name<>'.')and(sr.Name<>'..') then
        BEGIN
          StringGrid1.Cells[0,StringGrid1.RowCount - 1] := SP+'\'+sr.Name;
          StringGrid1.RowCount  := StringGrid1.RowCount + 1;
          FindAll(SP+'\'+sr.Name)  //递归查找下一个目录
        END
        else
        begin
          If (sr.Name<>'.')and(sr.Name<>'..') then
          begin
            StringGrid1.Cells[0,StringGrid1.RowCount - 1] := SP+'\';
            StringGrid1.Cells[1,StringGrid1.RowCount - 1] := sr.Name;
            StringGrid1.Cells[2,StringGrid1.RowCount - 1] := IntToStr(sr.Size);
            StringGrid1.RowCount  := StringGrid1.RowCount + 1;
          End;
        end;
        fr := FindNext(sr);
      end;
      FindClose(sr);
    end;procedure TMainForm.Button1Click(Sender: TObject);
    begin
      InitStringGrid; //初始化 StringGrid1
      FindAll('E:\ftp\');
    end;END.