Go to: Synopsis. Return value. Related. MEL examples.

Synopsis

fopen [string] string

fopen is NOT undoable, NOT queryable, and NOT editable.

This command defaults to opening a file for writing and returns a file identifier. The optional mode string may be one of the following:
"w" open file for writing (destroys prior contents of file).
"a" append for writing (appends to end of file).
"r" open for reading.
A "+" optionally after the mode character opens for both reading and writing. If an error occurs while attempting to open the file, fopen will return zero. For more information see the C implementation of the function fopen.

Return value

int File id

Related

fclose, feof, fflush, fgetline, fgetword, fprint, fread, frewind, fwrite, pclose, popen

MEL examples

// Open a file for writing, the default behavior of the command
//
$exampleFileName = ( `internalVar -userTmpDir` + "example.tmp" );
$fileId=`fopen $exampleFileName`;
fprint $fileId "Hello there\n";
fclose $fileId;

// OR

// Do the same as above, but include the "w" argument to explicitly
// say that we wish to open the file for writing
//
$exampleFileName = ( `internalVar -userTmpDir` + "example.tmp" );
$fileId=`fopen $exampleFileName "w"`;
fprint $fileId "Hello there\n";
fclose $fileId;