int :file-force-contents ( string $PATH , string $CONTENTS )
Writes contents of $CONTENTS to the file specified by $PATH. If the file already exists, it is overwritten.
Practically, this is identical to calling :f-rewrite
, :f-write
and :f-close
.
Contrary to :file-put-contents
, if any parts of the directory structure specified in $PATH do not exist, this function will perform a :dir-force
call in an attempt to create them.
Returns number of bytes written to disk, or -1 on failure.
# :file-force-contents example !fun :save-config :set &json :json-encode $CONFIG :set &path :add =CONFIG-PATH =CONFIG-FILE :set &fpc :file-force-contents $path $json !if :ge $fpc i0 :writeln s'Configuration saved successfully.' !else :writeln s'Unable to save config file!' !fi !nuf
wikipage modified on 2014/0906/1241