Equinox Online Help - Language Reference - A to Z

Home

FileOpen

Applies to
SyntaxFileOpen PathExpression, ModeExpression, HandleItem
Action[Statement] Opens a random file containing binary data or a sequential file containing text data.
ScopeUsable anywhere
Notes

This statement can be used to directly access files from a method. The file name is specified in the PathExpression parameter and the ModeExpression parameter indicates the type of file access together with an optional share mode.

In order to make the file appear on the server, prepend "SERVER:" (in any case) to the PathExpression. This prefix is ignored by the single user version. If the path specification is a relative one, it will start from the program directory - the Eqserver.exe directory for server files, and the Equinox.exe or Equinet.exe directory for everything else.

Do not use method language file handling to manipulate Equinox files.

The following constants specify the types of file access:

Mode ConstantsDescription
RandomReadOnlyAllows read operations on random files
RandomReadWriteAllows both read and write operations on random files. If the file does not exist, it is created
RandomCreateCreates a read-write random file. If a file with the same name already exists, the previous file is destroyed
StreamReadOnlyAllows read operations on sequential files
StreamCreateCreates a sequential file. If a file with the same name already exists, the previous file is destroyed
StreamAppendOpens a file and sets the file pointer to the end before every write operation. If the file does not exist, it is created

The share mode dictates what happens if someone else tries to open the file.The default is no file sharing: the file can be opened with no file sharing by any station as many times as required, but attempts to share the file using one of the modes below fail if it is already open. (so-called "compatibility mode"). File sharing must be enabled in the operating system.

Note that the StreamReadWrite mode, available in Equinox version 2 and above, is now obsolete. Previously compiled code will continue to work as before, but in edited code you should substitute one of the other stream modes.

If sharing support is required, the following constants can be added to the mode:

Share constantsDescription
DenyReadWritePrevents other users from readind or writing to the file
DenyWritePrevents other users from writing to the file
DenyReadPrevents other users from reading to the file
DenyNoneAllows other users to share the file

The HandleItem parameter is a variable of type Handle, which receives the handle of the file that was opened. If an error occurs, the value in HandleItem is undefined. You should always check the system workarea SysError, which is set to a non-zero value if an error occurs, otherwise zero.

CategoryFile IO
See Also FileClose, FileCloseAll, FileDelimiters, FileInput, FileInputLine, FileLock, FileMovePosition, FileOpen, FilePosition, FilePrint, FileRead, FileReadLine, FileReadBinary, FileReadFile, FileUnlock, FileWrite, FileWriteBinary, FileWriteFile
Example

The following example opens a binary file for reading and writing whilst denying other network users the rights to read or write to the file.

handle hnd

FileOpen "c:\test\test.dat", RandomReadWrite + DenyReadWrite, hnd

if syserror then Alert "File Opening Error"

The following example opens a binary file for reading and writing whilst denying other network users the rights to read or write to the file, using a UNC path for the file.

handle hnd

FileOpen "\\MYSERVER\apps\test\test.dat", RandomReadWrite + DenyReadWrite, hnd

if syserror then Alert "File Opening Error"