Vely logo install | documentation | examples | changelog
16.10.0 released May 10, 2023

Purpose: Open file for reading and writing.

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

Opens <file> for reading and writing and creates an open file variable identified by <file id>, which can be created with optional "define". If you supply your own <file id>, it should be of type "vely_file*".

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

You can obtain the status of file opening via optional <status> (in "status" clause), which can be created with optional "define". The <status> is VV_OKAY if file is opened, or VV_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.
// Create new file, or truncate an old file if it exists
open-file "testwrite" file-id define nf new-truncate

// Write 25000 rows
num i;
for (i = 1; i <= 25000; i++) {
    (( define line
    some text in line <<p-out i>>
    )) bytes-written define line_len notrim
    write-file file-id nf from line length line_len

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

// Read all 25000 rows back, and print them out
for (i = 1; i <= 25000; i++) {
    read-file file-id nf  to define one_item
    p-out one_item

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

See also
Files ( 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)

Copyright (c) 2017-2023 Dasoftver LLC