GOLF(2gg)

πŸ“¦ version 601.4.41, in ubuntu questing

πŸ’… GOLF(2gg) β€” no cap, it's the manual

okay bestie, welcome to the GOLF(2gg) page, Development section, and we're about to talk about one little statement that does a LOT 🫢


✨ NAME ✨

open-file β€” the files girlie πŸ’– (files)


🎯 PURPOSE 🎯

Open a file for reading and writing. Both. At once. It's giving versatile πŸ‘‘


πŸ“œ SYNTAX πŸ“œ

open-file <file name> file-id <file id> \
    [ new-truncate ] \
    [ status <status> ]

🌸 DESCRIPTION 🌸

So here's the vibe: this opens the file you name in <file name> for reading and writing, and it makes an open file variable for you, identified by <file id>. That's your handle, your little keychain, your main character ID πŸ”‘

<file name> can be a whole full path name, or a path relative to the application home directory (peep directories for that one, iykyk).

Wanna know if it actually worked? You can grab the status of the file opening through the <status> number β€” that's the "status" clause, bestie. And the <status> is gonna be:

  • GG_OKAY β€” slay, the file is opened πŸ’–
  • GG_ERR_OPEN β€” nope, could not open the file 😭

And if you use the "new-truncate" clause? Then a new file is created if it doesn't exist, or it gets truncated if it does. Fresh start energy ✨


πŸ’« EXAMPLES πŸ’«

okay so here's a whole little saga: create a file (or truncate an existing one), write 25,000 rows, read those rows back, display them, then close the file. Obsessed, honestly 🌈

%% /ofile public
    // Create new file, or truncate an old file if it exists
    open-file "testwrite" file-id nf new-truncate

    // Write 25000 rows
    start-loop repeat 25000 use i
       (( line
       @some text in line <<print-out i>>
       )) notrim
       string-length line to line_len
       write-file file-id nf from line length line_len
    end-loop

    // Rewind back to the beginning
    file-position set 0 file-id nf

    // Read all 25000 rows back, and print them out
    read-file file-id nf  to whole_file
    print-out whole_file

    // Close the file
    close-file file-id nf
%%

πŸ‘€ SEE ALSO πŸ‘€

Files

the whole squad fr fr, go read up on all of them:

change-mode close-file copy-file delete-file file-position file-storage file-uploading lock-file open-file read-file read-line rename-file stat-file temporary-file uniq-file unlock-file write-file

Also: See all documentation πŸ“š


reminder bestie: GG_OKAY means opened, GG_ERR_OPEN means it could not open the file. always check your status clause, don't just assume πŸ’…

mwah, that's the whole page πŸŽ€ this GOLF(2gg) situation is from $VERSION, dated $DATE, and yes she ate, no crumbs left. bye bestie πŸ¦‹

πŸ“¦ where this page comes from