如何进行全硬盘文件查找。比如,在d盘下查找所有文件名后缀为.txt的文件名及其绝对路径。望各大侠援助!!!

解决方案 »

  1.   

    本人已经开有一贴
    http://community.csdn.net/Expert/topic/3831/3831624.xml?temp=.6947138
      

  2.   

    用findfirts,findnext语句
    要用递归.
    心情不好,不多写了,下面只是一个用findfirts,findnext语句的参考例子.procedure TForm1.Button1Click(Sender: TObject);
    var
        sr: TSearchRec;
    begin
    if Trim(filepath)<>'' then
    begin
     if FindFirst(filepath+'*.txt', faAnyFile, sr) = 0 then      //所有.txt文件
        begin
          repeat
            if (sr.Attr and faAnyFile) = sr.Attr then //faAnyfile 所有文件
            begin
              shellexecute(0,'open',pchar(Edit1.Text+sr.Name),nil,nil,sw_show);//打開
            end;
          until FindNext(sr) <> 0; //查找下一個
          FindClose(sr); //結束查找
        end;
    end;
    end;
    // findfirst 語句,找到返回值為0,否則不為0