Поиск файлов в папке и во всех подкаталогах
procedure GetAllFiles( mySearchText:String; Path: string; Lb: TListBox );
var
BigTextFile:TextFile;
BigText,BigTextUrl:string;
sRec: TSearchRec;
isFound: boolean;
stroka:integer;
begin
isFound := FindFirst( Path + '*.*', faAnyFile, sRec ) = 0;
while isFound do
begin
if ( sRec.Name <> '.' ) and ( sRec.Name <> '..' ) then
begin
stroka:=0;
if ( sRec.Attr and faDirectory ) = faDirectory then
GetAllFiles( mySearchText, Path + '' + sRec.Name, Lb )
else begin
BigTextUrl:= (Path + '' + sRec.Name);
AssignFile(BigTextFile,BigTextUrl);
Reset(BigTextFile);
while not Eof(BigTextFile) do
begin
stroka:=stroka+1;
ReadLn(BigTextFile, BigText);
if pos(mySearchText,BigText)>0 then Lb.Items.Add (sRec.Name+'('+Path+', '+inttostr(stroka)+')');
end;
CloseFile(BigTextFile);
end;
end;
Application.ProcessMessages;
isFound := FindNext( sRec ) = 0;
end;
FindClose( sRec );
end;
GetAllFiles( mySearchText, url, listbox1 );
//mySearchText-искомый текст, url-директория, listbox1-вывод