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

coco at jechar.ca coco at jechar.ca
Mon Dec 19 12:42:40 EST 2022


Charlie Replies:

I am not sure I understand how you would keep the two
files in sync without random access ? Unless you are
essentially talking about using FILE.TXT and FILE.NEW where
FILE.NEW starts out empty and gets it's input from FILE.TXT after
FILE.TXT has been processed. Them manually from the OS after one
could delete FILE.TXT copy FILE.NEW to FILE.TXT and then delete FILE.NEW

I assume that the command

OPEN "I", #4,"FILE.NEW" creates a new empty text file named FILE.NEW ?



On 2022-12-19 10:32, William Astle via Coco wrote:
> 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