Script functions reference > Script functions in alphabetical order > F > FileOpen

FileOpen
Syntax
FileOpen(filename, mode);
filename
mode
A string specifying the mode, i.e. what to do with the file. In binary modes, translations involving carriage-return and line-feed characters are suppressed. The following modes are available:
w – (write) overwrite existing file.
wb – (write binary) overwrite existing file binary.
a – (append) write at the end of existing file. If there is no existing file, the file is created.
ab – (append binary) write at the end of existing file binary. If there is no existing file, the file is created.
r – (read) read existing file. If there is no existing file, or if the file cannot be found, the call fails.
rb – (read binary) read existing file binary. If there is no existing file, or if the file cannot be found, the call fails.
Description
Opens the specified file for reading or writing according to mode specified. See also IoErrText.
Returns
A number indicating whether the file was successfully opened.
0
>0
Failure. This value can be sent to IoErrText which will return an error text for the failure.
Example
//Open myfile.txt for writing and store the returned value in $err
 
$err = fileopen("D:\documents\myfile.txt", "w");
 
//If the action was unsuccessful, pass the error value
//to ioerrtext and store the error text returned by
//ioerrtext in $errtext.
//Send the error text to the log file
 
if(num($err)!=0)
{
$errtext=ioerrtext($err);
log(0,"Errortext "+$errtext);
}
OpenText StreamServe 5.6.2 Updated: 2018-01-26