"Appending" at beginning of file

B

Bruno

Hi all!

I'm new to this group, and I have a question: is there any way to open
a file and write something _before_ it's contents? Example:

original file:

ABCDE

appended file:

FG <---------------- put before the original content.
ABCDE

At present, i have to create a new file, write the new content, then
copy the contents of the original file to the new file. This is such a
pain in the neck!

Best regards,

Bruno.
 
V

Victor Bazarov

Bruno said:
I'm new to this group, and I have a question: is there any way to open
a file and write something _before_ it's contents?
No.

[..]

At present, i have to create a new file, write the new content, then
copy the contents of the original file to the new file. This is such a
pain in the neck!

Perhaps your neck needs to review its pain threshold.

V
 
T

Tomás

Bruno posted:

At present, i have to create a new file, write the new content, then
copy the contents of the original file to the new file. This is such a
pain in the neck!


That's how it's done portably as far as I know.


-Tomás
 
M

mlimber

Bruno said:
is there any way to open
a file and write something _before_ it's contents?

If you're doing that a lot, consider other alternatives so you can use
standard file access operations:

1. Reverse the order of the data in your file so that inserting data at
the beginning means writing to the end.

2. Add to the file some indicator of a data item's place in the list,
and then sort the data appropriately when you read it in (occasionally
you might also re-write the whole file in the sorted order to ease load
times).

Etc.

Cheers! --M
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,767
Messages
2,569,572
Members
45,045
Latest member
DRCM

Latest Threads

Top