Is that a fact?Documentation shows there is an append for the open file command
- -
The politest words I can think of are 'inadequately documented'.
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
Is that a fact?Documentation shows there is an append for the open file command
Code: Select all
on mouseUp
set the ink of me to srcCopy
answer file "Choose a text file to import"
if the result = "cancel"
then exit mouseUp
else
put URL ("file:" & it) into pTEXT
put fld "fTEXT" into aTEXT
put pTEXT & cr & aTEXT into nTEXT
put nTEXT into URL ("file:" & it)
end if
end mouseUp
Code: Select all
on mouseUp
set the ink of me to srcCopy
answer file "Choose a text file to add extra text at the end"
if the result = "cancel"
then exit mouseUp
else
open file URL ("file:" & it) for append
put (cr & fld "fTEXT") into nTEXT
write nTEXT to file URL ("file:" & it)
close file URL ("file:" & it)
end if
end mouseUp
Yes, I suppose when looking up "append" (as, like you, I did) it would be more helpful if that word was also "related" to "open file". The dictionary is very good at that, usually, but not always.The politest words I can think of are 'inadequately documented'.
I believe the need to specify the I/O mode when first opening a file is a function of the OS.
EOF is a constant for the flag that signifies the end of a file. Like CR, tab, and other constants, it does nothing by itself, and what we choose to do with it is up to us.I just wanted to make sure that using "EOF" does what it purports, appends the text written to the end of any text already in the remote file.
Code: Select all
read from file tFile until CR
Code: Select all
read from file tFile until EOF
Code: Select all
seek in file tFile until EOF
write tSomeData to file tFile
It looks like you found the Glossary entry. The Dictionary entry has more details and an example as you'd expect.richmond62 wrote: ↑Thu Dec 22, 2022 9:12 amIs that a fact?Documentation shows there is an append for the open file command
-
Screen Shot 2022-12-22 at 10.08.32 am.png
-
The politest words I can think of are 'inadequately documented'.
Code: Select all
open file filePath for append
Code: Select all
Open file for append...
write to file...
Code: Select all
Open file for text write...
write <some text> at EOF
Code: Select all
write <some text> at end
Indeed I did:It looks like you found the Glossary entry.
That doesn't work because the open file command doesn't take a URL reference, it only needs a file path.open file URL ("file:" & it) for append
With logs, the size of data previously written to the file would only come into play with options that require reading the file into memory, appending it there, and then writing the whole thing back out to disk. The downsides of options using unnecessary reads were noted in earlier replies.stam wrote: ↑Thu Dec 22, 2022 6:10 pmWhat I'm not clear about is howis any different fromCode: Select all
Open file for append... write to file...
or evenCode: Select all
Open file for text write... write <some text> at EOF
given that for logging the text isn't going to be humungous, so efficiency improvements can't be that great... or are they?Code: Select all
write <some text> at end
Code: Select all
write tData to file tFile at 1000
This would seem to imply that where a log is exclusively used by only one process, the functional benefit is negligible.Append Mode
When fd is opened in append mode (via O_APPEND), writes do not occur at the file descriptor’s current file position. Instead, they occur at the current end of the file. For example, assume that two processes intend to write to the end of the same file. This is common: consider a log of events shared among many processes. At the start, their file positions are correctly set to the end of the file. The first process writes to the end
of the file. Without append mode, once the second process attempts the same, it will end up writing not to the end of the file, but to the offset that was the end of the file, before the data that the first process wrote. This means that multiple processes can never append to the same file without explicit synchronization between them because they will encounter race conditions. Append mode avoids this problem. It ensures that the file position is always set to the end of the file so all writes always append, even when there are multiple writers. You can think of it as an atomic update to the file position preceding each write request. The file position is then updated to point at the end of the newly written data. This will not matter to the next call to write(), as it updates the file position automatically, but it might matter if you next call read() for some odd reason.
Append mode makes a lot of sense for certain tasks, such as the aforementioned writing out of log files, but little sense for much else.
when the documentation is 'scant' ?take a URL reference, it only needs a file path.
Code: Select all
on mouseUp
set the ink of me to srcCopy
answer file "Choose a text file to import"
if the result = "cancel"
then exit mouseUp
else
put URL ("file:" & it) into pTEXT
put fld "fTEXT" into aTEXT
put pTEXT & cr & aTEXT into nTEXT
put nTEXT into URL ("file:" & it)
end if
end mouseUp
I was careless, or at least inattentive, like you.
Possibly, and I love you too.But I was lazy, like you.
URL syntax is used to move data among complete files. If you don't need to append an existing file, you'd have no need to use append.