GOLF(2gg)

NAME
open-file - (files)

PURPOSE
Open file for reading and writing.

SYNTAX

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

DESCRIPTION
Opens file given by <file name> for reading and writing and creates an open file variable identified by <file id>.

<file name> can be a full path name, or a path relative to the application home directory (see directories).

You can obtain the status of file opening via <status> number (in "status" clause). The <status> is GG_OKAY if file is opened, or GG_ERR_OPEN if could not open file.

If "new-truncate" clause is used, a new file is created if it doesn't exist, or it is truncated if it does.

EXAMPLES
Create a file (or truncate an existing one), write 25,000 rows and the read back those rows and display them, then close file:

        %% /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

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 See all documentation