|
On-Line News | April 5, 2000 No. 94 OPEN# File Mode ParameterThe OPEN# language statement opens and, if necessary, creates a data file on a specified stream. The stream must have been previously selected to a native operating system directory with the SELECT# statement. Any file previously open on the stream is first closed. The correct syntax for OPEN# is as follows: The mode parameter determines the operations that
will be performed on the opened file. In
addition, an optional translation flag may be appended to the mode to specify how to
handle line feeds in an MS-DOS environment (these flags are ignored under UNIX). If a mode parameter is not specified, then a
default mode of r+b is assumed, indicating both read and write operations will
be performed on a binary file, and that an error will be generated if the file does not
exist. The mode parameter and optional
translation flags that comprise the file mode argument passed to OPEN# are outlined below. r The file will be opened as read only. The open will fail if the file does not exist. w The file will be opened as write only. If the file exists then OPEN# overwrites the file and destroys its contents. If the file does not exist, it is created. a The file will be opened in append mode. OPEN# will create the file if it does not exist. If the file already exists, any data written to the file will be appended to the end of the file. The EOF marker (CTRL-Z) is not moved when a is passed as the file mode parameter, and data will be appended after the EOF marker, if one exists. r+ The
file will be opened for both read and write operations. The open will fail if the file does not exist. w+ The file will be opened for both read and write operations. If the file exists, OPEN# overwrites the file and
destroys its contents. A new file is created
if one does not already exist. a+ The file will be opened for both reading and appending records. A new file is created if one does not already
exist. The file pointer can be repositioned, but it is always moved back to the end of the
file before any write operation is carried out--existing records cannot be
overwritten/updated. The file is checked for
an EOF file marker. If an EOF marker exists, it is removed before new data is written to
the file and restored after the write process is complete. b
The file will be opened in binary
(non-translated) mode. Translations involving
carriage-return and linefeed characters are suppressed.
|