suve
Warning: Illegal string offset 'doublequoteopening' in /usr/home/svgames/domains/svgames.pl/public_html/dokuwiki/inc/parser/xhtml.php on line 766 Warning: Illegal string offset 'doublequoteclosing' in /usr/home/svgames/domains/svgames.pl/public_html/dokuwiki/inc/parser/xhtml.php on line 774 Warning: Illegal string offset 'doublequoteopening' in /usr/home/svgames/domains/svgames.pl/public_html/dokuwiki/inc/parser/xhtml.php on line 766 Warning: Illegal string offset 'doublequoteclosing' in /usr/home/svgames/domains/svgames.pl/public_html/dokuwiki/inc/parser/xhtml.php on line 774

awful: function: f-open

Available since rev.36 (v.0.5.0).

Declaration

file :f-open ( string $PATH , string $MODE )

Summary

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.

Example

# :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