Link to home
Start Free TrialLog in
Avatar of PieterJ
PieterJ

asked on

Textfile

Hi guys,

Say for instance I have 3 .rtf files, how can I actually add/append them together (So that I only have one file) before doing any work on it ?
Here is the Code I use for one, but somewhere in between I have to append 3 different .rtf files :

procedure TForm1.Button1Click(Sender: TObject);
var
  F : TextFile;
  aString : String;
begin
  aString := ExtractFileDir(ParamStr(0)) + '\Test.rtf';

  AssignFile(F, aString);

  Reset(F);

  while not EOF(F) do
  begin
    Readln(F, bString);
   
    // Do whatever
  end;

  CloseFile(F);
end;


Thanks

Pieter
ASKER CERTIFIED SOLUTION
Avatar of wimmeyvaert
wimmeyvaert

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Open your first file with Append(f) so that the cursor is (figuratively speaking) at the end of the file.

Then open the other 2 files with Reset(f) and in your While Not EOF(f) loop, add each line to File 1. i.e.

procedure TForm1.Button1Click(Sender: TObject);
var
 F, F2 : TextFile;
 aString, bString : String;
begin
 aString := ExtractFileDir(ParamStr(0)) + '\Test.rtf';

 AssignFile(F, aString);
 Append(F);

 aString := ExtractFileDir(ParamStr(0)) + '\Test2.rtf';
 
 AssignFile(F2, aString);
 Reset(F2);

 while not EOF(F2) do
 begin
    Readln(F2, bString);
    Writeln(F, bString);
 end;

 CloseFile(F2);
 CloseFile(F);
end;

J.

Avatar of nestorua
nestorua

HI,
When reading the comments above I seem to find myself in Turbo Pascal 7.0 again. It's very pleasant remembrances but why don't use TFileStream or TMemoryStream technique?
Sincerely,
Nestorua.