Append a record to the end of a text file: Difference between revisions
Append a record to the end of a text file (view source)
Revision as of 22:58, 29 May 2020
, 4 years ago→{{header|Wren}}: Discovered an undocumented method to append a record to an existing file.
(→{{header|Wren}}: Discovered an undocumented method to append a record to an existing file.) |
|||
Line 3,819:
Although Wren has basic classes to work with the file system, these are only available when creating standalone scripts using the command line interpreter (CLI) and not when Wren is being embedded. In the latter case it relies on the host application for such support.
To append a record to an existing file in a CLI script, a little digging is required as the method to do this (''File.openWithFlags'') is currently undocumented. However, the following works fine.
<lang ecmascript>import "io" for File, FileFlags▼
▲<lang ecmascript>import "io" for File
var records = [
Line 3,845 ⟶ 3,841:
// Append the new record to the file and close it.
File.
file.writeBytes(newRec + "\n")
}
Line 3,883 ⟶ 3,878:
|}
<br>
=={{header|Yabasic}}==
<lang Yabasic>a = open("passwd", "a") // Open the file for appending, i.e. what you write to the file will be appended after its initial contents.
|