![]() |
|
#1
|
||||
|
||||
![]() Помогите исправить поисковик файлов по расширеню
В общем использую следующий алгоритм для поиска Код:
procedure TdlgSearchResults.SearchDir(Dir,Ext: string); var SR: TSearchRec; FindRes: Integer; Item:TListItem; begin FindRes := FindFirst(Dir + Ext, faAnyFile, SR); while FindRes = 0 do begin if ((SR.Attr and faDirectory) = faDirectory) and ((SR.Name = '.') or (SR.Name = '..')) then begin FindRes := FindNext(SR); Continue; end; if ((SR.Attr and faDirectory) = faDirectory) then begin SearchDir(Dir + SR.Name + '\',Ext); FindRes := FindNext(SR); Continue; end; //Files.Add(Dir + SR.Name);//Add to list Item:=lvFiles.Items.Add; Item.Caption:=SR.Name; Item.SubItems.Add(IntToStr(SR.Size)); Item.SubItems.Add(Dir); //showmessage(dir+sr.Name); FindRes := FindNext(SR); end; FindClose(FindRes); end; При поиске к примеру *p* работает отлично, то же самое и при поиске без точки *exe*. — Как тебя понимать? — Понимать меня не обязательно. Обязательно меня любить и кормить вовремя. На Delphi, увы, больше не программирую. Рекомендуемая литература по программированию |
#2
|
|||
|
|||
![]() Попробуй это:
Код:
function TForm1.FileMaskEquate(F, M: string): boolean; var Fl, Ml: integer; // length of file name and mask Fp, Mp: integer; // pointers begin F := UpperCase(F); M := UpperCase(M); result := true; Fl := length(F); Ml := length(M); Fp := 1; Mp := 1; while Mp <= Ml do begin // wildcard case M[Mp] of // '?': begin // if one any char inc(Mp); // next char of mask inc(Fp); // next char of file name end; // '*': begin // if any chars if Mp = Ml then exit; // if last char in mask then exit if M[Mp + 1] = F[Fp] then begin // if next char in mask equate char in Inc(Mp); // file name then next char in mask and end else begin // else if Fp = Fl then begin // if last char in file name then result := false; // function return false exit; // end; // else, if not previous, then inc(Fp); // next char in file name end; // end; // else begin // other char in mask if M[Mp] <> F[Fp] then begin // if char in mask not equate char in result := false; // file name then function return exit; // false end; // else if (Mp=Ml) and (Fp<>Fl) then begin Result:=false; exit; end; inc(Fp); // next char of mask inc(Mp); // next char of file name end // end; end; end; procedure TdlgSearchResults.SearchDir(Dir: string; var Ext: string); var SR: TSearchRec; FindRes: Integer; Item:TListItem; begin FindRes := FindFirst(Dir + '*.*', faAnyFile, SR); while FindRes = 0 do begin if ((SR.Attr and faDirectory) = faDirectory) and ((SR.Name = '.') or (SR.Name = '..')) then begin FindRes := FindNext(SR); Continue; end; if ((SR.Attr and faDirectory) = faDirectory) then begin SearchDir(Dir + SR.Name + '\',Ext); FindRes := FindNext(SR); Continue; end; //Files.Add(Dir + SR.Name);//Add to list if FileMaskEquate(SR.Name, Ext) = true then begin Item := lvFiles.Items.Add; Item.Caption := SR.Name; Item.SubItems.Add(IntToStr(SR.Size)); Item.SubItems.Add(Dir); end; //showmessage(dir+sr.Name); FindRes := FindNext(SR); end; FindClose(FindRes); end; |
#3
|
||||
|
||||
![]() Спасибо, все работает
![]() — Как тебя понимать? — Понимать меня не обязательно. Обязательно меня любить и кормить вовремя. На Delphi, увы, больше не программирую. Рекомендуемая литература по программированию |