如何像Windows的搜索一样,能够搜索出来指定文件名进行搜索。急急
例如;
给出*.EXE就能够搜索出来制定文件夹的所有exe文件
不知道该如何用delphi实现

解决方案 »

  1.   

    我的这段写来是为了查找后缀名为三位的
    要改成*的通配符还要多写个函数procedure TForm1.seachfile(path : string);
    var
      sr: TSearchRec;
       path : string;
    begin
    path:='c:\';
    if FindFirst(path+'\*.*',faanyfile, sr) = 0 then
    repeat
    if (sr.name<>'.') and (sr.name<>'..') then
    //如果是目录
    if (sr.Attr and fadirectory) = fadirectory then
      SeachFile(path+'\'+sr.name)
    else
    begin
    //如果是后缀名相同于EDIT2的内容
    if lowercase(strright(sr.name,4))=lowercase(strright(edit2.text,4)) then
     sl.add(path+'\'+sr.name);
     end;
    until findnext(sr)<>0;
     findclose(sr);
    end;
      

  2.   

    我的一段代码:
    procedure TCopyFileThread.FindFiles(AFileName, APath: string;
      AFileStrLst: TStringList);
    var
      FSearchRec, DSearchRec: TSearchRec;
      FindResult: integer;  function IsDirNotation(ADirName: string): Boolean;
      begin
        Result := (ADirName = '.') or (ADirName = '..');
      end;begin
      APath := GetDirectoryName(APath);
      FindResult := FindFirst(APath + AFileName, faAnyFile + faHidden +
        faSysFile + faReadOnly, FSearchRec);
      try
        while FindResult = 0 do
        begin
          AFileStrLst.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 not
            IsDirNotation(DSearchRec.Name) then
            FindFiles(AFileName, APath + DSearchRec.Name, AFileStrLst);
          FindResult := FindNext(DSearchRec);
        end;
      finally
        FindClose(FSearchRec);
      end;
    end;