Go to: Return value. Related commands. Examples.

Synopsis

fopen <string> [ <string> ]

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

Related commands

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

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;