Vely logo install
examples
documentation

Vely 15.2.0 released on Jan 18, 2023
Articles updated Jan 17, 2023

open-file


Issues with this documentation page? Report here.

Purpose:


Open file for reading and writing.

Syntax:



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


Description:


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.

Examples:



// 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) 2022 DaSoftver LLC. Vely is a trademark of Dasoftver LLC. The software and information herein are provided "AS IS" and without any warranties or guarantees of any kind. Vely elephant logo (c) 2022 DaSoftver LLC. This web page is licensed under CC-BY-SA-4.0.