Показать сообщение отдельно
  #4  
Старый 28.10.2010, 13:07
Аватар для Страдалецъ
Страдалецъ Страдалецъ вне форума
Гуру
 
Регистрация: 09.03.2009
Адрес: На курорте, из окна вижу теплое Баренцево море. Бррр.
Сообщения: 4,723
Репутация: 52347
По умолчанию

Вот вам вариант, разбирайтесь:
Код:
Type
  TReplace = record
   FindText: String;
   ReplaceText: String;
  end;
Var
   Template: Array of TReplace;
   FileInfo: TSearchRec;
   InFile,OutFile: TextFile;
   s,FilePath: String;
   i: Integer;
begin
 SetLength(Template, 3);
 Template[0].FindText := 'мама';
 Template[0].ReplaceText := 'папа';
 Template[1].FindText := 'мыла';
 Template[1].ReplaceText := 'купил';
 Template[2].FindText := 'раму';
 Template[2].ReplaceText := 'машину';

 FilePath := 'd:\1\';
 if FindFirst(FilePath + '*.htm', faAnyFile, FileInfo) = 0
 then begin
      try
       repeat
        if (FileInfo.Name = '.') or (FileInfo.Name = '..')
           or (FileInfo.Attr and faDirectory <> 0) then Continue;
        AssignFile(InFile, FilePath + FileInfo.Name);
        Reset(InFile);

        AssignFile(OutFile, FilePath + '~' + FileInfo.Name);
        Rewrite(OutFile);

        while not Eof(InFile)
        do begin
           ReadLn(InFile, s);
           for i := 0 to Length(Template) - 1
           do s := StringReplace(s, Template[i].FindText, Template[i].ReplaceText,[rfReplaceAll]);
           WriteLn(OutFile, s);
        end;

        CloseFile(OutFile);
        CloseFile(InFile);

       until FindNext(FileInfo) <> 0;
      finally
       FindClose(FileInfo);
      end;
      end;
 end.
__________________
Жизнь такова какова она есть и больше никакова.
Помогаю за спасибо.
Ответить с цитированием