peterjoustra
asked on
file writing without overwriting
How can i insert text from multiple files in one file? The file where i would want to write to doesnt have an extension.
My problem is that I want to insert data in a file that already contains data. when i do something like this:
try
// source file
assignfile(sourcefile,'C:\
reset(sourcefile);
// destination file
Rewrite(destination,'c:\de
append(destination);
pointer := eof(destination);
while not eof(source') do
begin
ReadLn( source', line);
writeln(destination,line);
end;
finally
CloseFile(source');
CloseFile(destination);
end;
when i run this multiple times, it overwrites data in the destination file. that sux.
>Rewrite(destination,'c:\d estination );
allways creates a new file, do a check for existence before using rewrite , if the file not exists, otherwise use reset
look at fileexists-function
meikl ;-)
allways creates a new file, do a check for existence before using rewrite , if the file not exists, otherwise use reset
look at fileexists-function
meikl ;-)
or do as drdelphi suggested
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Why does this question have 'Pending delete' status?
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:
Accept answer from DrDelphi
Please leave any comments here within the next seven days.
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
Paul (pnh73)
EE Cleanup Volunteer
I will leave a recommendation in the Cleanup topic area that this question is:
Accept answer from DrDelphi
Please leave any comments here within the next seven days.
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
Paul (pnh73)
EE Cleanup Volunteer
Well, I have to disagree again. DrDelphi's solution doesn't add one file at the end of another. It could be modified to do so, of course.
Regards, Geo
Regards, Geo
Objection considered.
I will leave a recommendation in the Cleanup topic area that this question is:
Accept answer from geobul
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
Paul (pnh73)
EE Cleanup Volunteer
I will leave a recommendation in the Cleanup topic area that this question is:
Accept answer from geobul
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
Paul (pnh73)
EE Cleanup Volunteer
Behold:
var list:TstringList;
begin
list:=Tstringlist.create;
List.LoadFromFile('Z:\myfi
List.add('this is a new line '+TimeTostr(now));
List.add('So is this one '+TimeTostr(now));
List.SaveToFile('Z:\myfile
FreeAndNil(list);
end;
Good luck!!