file :f-open ( string $PATH , string $MODE )
Opens a file on the disk and returns a handle allowing to perform subsequent operations on the file. The file should be later closed with a call to :f-close
.
MODE can be one of:
a
- to open the file in append mode (appends to end of existing files)r
- to open the file in read mode (reads from existing files) - default, invalid mode will revert to r
w
- to open the file in rewrite mode (overwrites existing files)If PATH does not exist (read), is not writeable (append/rewrite), or some other kind of error occurs, the returned filehandle will have its emodee flag set to einvalide. The simplest way to check if a file has been opened successfully is to cast it to bool - any invalid (or closed) handle will cast to FALSE.
# :f-open example :set &file :f-open s'example.txt' s"r" !if :not $file :writeln s'Unable to read from file!' :exit !fi :writeln :f-getln $file :f-close $file
wikipage modified on 2014/0611/1010