Append one file to other

 

You may copy contents of a first file to [new.$] file. After that, you may add contents of a second file to [new.$] and then delete first file and rename [new.$] file to name of the first file.

 

 

procedure TForm1.Button3Click(Sender: TObject);

var

  Str: string;

  F1, F2, F3: TextFile;

begin

  Label3.Caption:='Processing...';

  AssignFile(F1, Edit1.Text);

  AssignFile(F2, Edit2.Text);

  AssignFile(F3, 'new.$');

  Reset(F1);

  Reset(F2);

  Rewrite(F3);

  while not(EOF(F1)) do

  begin

    Readln(F1, Str);

    Writeln(F3, Str);

  end;

  while not(EOF(F2)) do

  begin

    Readln(F2, Str);

    Writeln(F3, Str);

  end;

  CloseFile(F1);

  CloseFile(F2);

  CloseFile(F3);

  DeleteFile(ExtractFileName(Edit1.Text));

  RenameFile('new.$', ExtractFileName(Edit1.Text));

  DeleteFile('new.$');

  Label3.Caption:='Processing done';

end;