[Coco] Updating RSDOS text files with DISK BASIC ver, 2,1

William Astle lost at l-w.ca
Mon Dec 19 10:32:15 EST 2022


On 2022-12-19 08:18, coco--- via Coco wrote:
> So I assume that for Basic you must
>     0. open file.TXT for input.
>     1. Read the entire file into an array.
>     2. Close the file.TXT and then Copy the original file to file.OLD
>     3. delete the original file.TXT
>     4. process the array
>     5. Open file.TXT for output
>       ( Am assuming this automatically creates empty file called file.TXT )
>     6. Save the contents of the array into file.TXT
>     7. Close
>     8. exit

I would use two files, say FILE1.TXT and FILE2.TXT. Then open FILE1.TXT 
for input and FILE2.TXT for output. Read some stuff from FILE1.TXT, 
update if required, then write to FILE2.TXT. Continue until EOF on 
FILE1.TXT. Then close both files, delete FILE1.TXT and rename FILE2.TXT 
to FILE1.TXT.

Then you aren't limited by the size of your array or whatever. Also, if 
your changes modify the size of any portion of the contents, the two 
file approach will work where an in-place update wouldn't.

There is also a random access mode ("D" or "R") but that isn't really 
suitable for text files or anything that doesn't have a fixed record 
size. It can be bodged into working, but it's a lot less pleasant than 
just using two files.


More information about the Coco mailing list