
22.03.2009, 13:19
|
Продвинутый
|
|
Регистрация: 13.02.2006
Адрес: Магнитогорск
Сообщения: 669
Репутация: 14745
|
|
Если я правильно понял:
Код:
{FileName - файл в котором имена файлов}
{SubStr - искомая строка}
{предполагается, что файлы лежат в той же папке, где и FileName}
procedure SearchText(FileName, SubStr: string);
var
i: integer;
Path, CurrentFile: string;
S: string;
begin
Path := ExtractFilePath(FileName); //Путь к файлам
Files := TStringList.Create; //Список файлов в паке
List := TStringList.Create; //Там будут строки
try
Files.LoadFromFile(FileName);
for i := 0 to Files.Count - 1 do begin
CurrentFile := Path + Files.Strings[i] + '.txt';
if FileExists(CurrentFile) = true then begin
AssignFile(input, CurrentFile);
Reset(input);
while not eof(input) do begin
Readln(S);
if Pos(SubStr, S) > 0 then List.Add(S);
end;
CloseFile(input);
end;
end;
List.SaveToFile(Path + 'List.txt');
except
List.Free;
Files.Free;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
SearchText('E:\1\Files.txt', 'aaa');
end;
|