Vely logo Empower C
install  tutorials  examples
documentation  license  about

12.1.0 released on Sep 19, 2022

read-file



PURPOSE:


Read file into a string variable.

SYNTAX:


read-file <file> to [ define ] <content> \
    [ position <position> ] \
    [ length <length> ] \
    [ status [ define ] <status> ]


DESCRIPTION:


If "position" and "length" clauses are not specified, read-file reads the entire text <file> into <content> (which can be created within a statement with "define" clause if it does not exist). If "position" clause is used, then reading starts at byte <position>, otherwise it starts at the beginning of the file. Position of zero (0) represents the beginning of the file. If "length" clause is used, then <length> gives the number of bytes to read (otherwise all through the end of the file is read).  <status> is an optional number variable (which can be created within the statement if "define" clause is used with "status"), and has a value of VV_ERR_OPEN if cannot open file, VV_ERR_READ if cannot read file, VV_ERR_POSITION if cannot position in the file, and the number of bytes read if successful (so either 0 or a positive number). If "length" goes over the length of the file, only what's available is read, and <status> will have the number of bytes actually read.

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

EXAMPLES:


To read the entire file and create both the variable that holds its content and the status variable:
read-file "/home/user/some_file" to define file_content status define st
if (st>=0) {
    @Read:
    @<hr/>
    p-web file_content
    @<hr/>
} else {
    @Could not read (<<pf-out "%lld" st>>)
}

"define" in both the content variable and the status are optional, so it could be:
num st;
char *file_content;

read-file "/home/user/some_file" to file_content status st

To read 10 bytes starting at position 20:
read-file "/home/user/some_file" to file_content position 20 length 10


SEE ALSO:


Files ( copy-file   delete-file   file_storage   file_uploading   lock-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. Icons copyright PaweĊ‚ Kuna licensed under MIT. This web page is licensed under CC-BY-SA-4.0.