This snippet shows how to open, read, write and close text files. This skeleton can be modified to handle any type of file, from untyped to text to typed files.
Text file manipulation
procedure CopyFile;
var
F1 : text;
F2 : text;
FN1 : string;
FN2 : string;
begin
FN1 := 'infile.txt';
FN2 := 'outfile.txt';
assign( F1, FN1 );
reset( F1 ); { open file for reading }
assign( F2, FN2 );
rewrite( F2 ); { open file for writing, destroying contents, if any }
while not EOF( F1 ) do
begin
readln( F1 );
{ file manipulation goes here }
writeln( F2 );
end;
close( F1 );
close( F2 );
end;
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.