Vely logo install examples
documentation about

14.2.0 released on Nov 29, 2022



Writes to a file.


write-file <file> from <content> \
    [ length <length> ] \
    [ position <position> | append ] \
    [ status [ define ] <status> ]


write-file writes <content> to <file>. If an optional "append" is used, the <content> is appended to the file; otherwise the file is overwritten with <content>, unless "position" clause is used in which case file is not overwritten and <content> is written at byte <position>.

File is created if it does not exist (even if "append" is used), unless "position" clause is used in which case it must exist.

If optional "length" clause is used, then only <length> bytes are written to the file.

The status of writing can be obtained via "status" clause, so <status> will be the number of bytes written (0 or positive), VV_ERR_OPEN if cannot open file, VV_ERR_WRITE if cannot write and VV_ERR_POSITION if cannot position in the file. Note that if less than requested number of bytes is written, that is considered an error and VV_ERR_WRITE will be reported.

You can specify full path of the file or a path relative to the application home directory (see how_vely_works).

If "length" is not used, then a string is written to a file, and the number of bytes written is the length of that string. If "length" is specified, then exactly <length> bytes is written and <content> can hold a binary value or a string.


To overwrite file "/path/to/file" with "Hello World":

write-file "/path/to/file" from "Hello World"

To append "Hello World" to file:

char *path="/path/to/file";
char *cont="Hello World";
write-file path from cont append

To write only 5 bytes (i.e. "Hello") and get status (if successful, number variable "st" would be "5"):

char *cont="Hello World";
write-file "file" from cont length 5 status define st

To write a string "Hello" at byte position 3 in the existing "file":

char *cont="Hello";
write-file "file" from cont position 3 status define st


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. Some icons copyright PaweĊ‚ Kuna licensed under MIT. Vely elephant logo copyright DaSoftver LLC. This web page is licensed under CC-BY-SA-4.0.