Показать сообщение отдельно
  #7  
Старый 04.02.2018, 14:31
Аватар для dr. F.I.N.
dr. F.I.N. dr. F.I.N. вне форума
I Like it!
 
Регистрация: 12.12.2009
Адрес: Россия, г. Новосибирск
Сообщения: 663
Версия Delphi: D6/D7
Репутация: 26643
По умолчанию

Код:
procedure CutTextFile(FileName: string; Parts: Integer);
var
  Src, Trg: TextFile;
  LineCount, LineCountInPart, i, j: Integer;
  tmp_str: string;
begin
  LineCount := 0;
  AssignFile(Src, FileName);
  Reset(Src);
  while not Eof(Src) do
  begin
    Readln(Src, tmp_str);
    Inc(LineCount);
  end;
  CloseFile(Src);
  if LineCount >= Parts then
  begin
    Reset(Src);
    LineCountInPart := Ceil(LineCount / Parts);
    for i := 1 to Parts do
    begin
      AssignFile(Trg, FileName + '.part' + IntToStr(i));
      Rewrite(Trg);
      j := 0;
      while (not Eof(Src)) and (j < LineCountInPart) do
      begin
        ReadLn(Src, tmp_str);
        Writeln(Trg, tmp_str);
        Inc(j);
      end;
      CloseFile(Trg);
    end;
    CloseFile(Src);
  end;
end;
__________________
Грамотно поставленный вопрос содержит не менее 50% ответа.
Грамотно поставленная речь вызывает уважение, а у некоторых даже зависть.
Ответить с цитированием