Function FOpen() Foundation

Opens a file at the operating system level.

FOpen( <cFilename>, [<nMode>]) --> nHandle
<cFilename> is a character string containing the name of a file including the drive and path if necessary.
<nMode> is an integer numeric value which specifies the mode for data access. The default value is zero, meaning that if <nMode> is not specified, the file is opened in "Read-only" and "Shared" mode. Symbolic constants for the argument <nMode> are defined in the header file "". The access mode for a single user or network access can be specified using these constants.
File access modes for FOpen() for single user access
Constant File operation
FO_READ *) read only
FO_WRITE write only
FO_READWRITE read and write
  1. default value
The three single station values can be modified for network use by adding one of the values from the next table. Using these additional constants, the access rights of several users to an individual file can be controlled.
File access modes for FOpen() for multi-user access
Constant Access right
FO_COMPAT only one user (like single station)
FO_EXCLUSIVE exclusive use (like single station)
FO_DENYWRITE other users have no write access
FO_DENYREAD other users have no read access
FO_DENYNONE other users have read and write access
  1. default value
File handle attributes for use with FCreate()
Constants Description
FA_INHERITABLE File handle can be used in child processes (RunShell())

FOpen() returns an integer numeric value. This number is the file handle provided by the operating system for <cFilename>. If an error occurs, the return value is -1 and the error code can be retrieved with FError().


The low level file function FOpen() opens a file at the operating system level. When the file named <cFilename> does not exist or cannot be opened in the access mode specified by <nMode>, FOpen() returns the value -1. The file error can then be determined from the error code returned by the function FError().

When the file is opened successfully, the return value of FOpen() (the file handle) must be assigned to a variable so that further file operations can be performed on the file.

Low level file functions do not use either the path set with SET PATH or specified with SET DEFAULT. Therefore, <cFilename> must be a complete file name with drive and path specified. If no drive or path is included in <cFilename>, the file is assumed to reside in the current directory.

// In the example, a file is opened for read 
// and write access. Read access by other users 
// is permitted. 

#include "" 

   LOCAL nHandle := FOpen("System.log", FO_READWRITE+FO_DENYWRITE) 

   IF FError() <> 0 
      ? "Error opening the file:", FError() 


If you see anything in the documentation that is not correct, does not match your experience with the particular feature or requires further clarification, please use this form to report a documentation issue.