BCX File Management Functions

FILELOCKED function

Purpose: FILELOCKED determines whether or not a file can be opened.


Syntax:

 RetVal% = FILELOCKED(FileName$)

Parameters:

  • RetVal% Returns the integer 1 if file cannot be opened or 0 if it can be opened.
  • FileName$ String literal or variable name of a file.

$FILETEST ON | OFF directive

Purpose: The $FILETEST ON or $FILETEST OFF directives specify whether or not to suppress the automatic failure checking when using OPEN and CLOSE statements.

In the C translation of OPEN and CLOSE statements, BCX automatically adds code to check for the existence of the file that is being opened or closed. If the file being opened does not exist, the program will exit and a "Can't open file FileName$" statement will be sent to stdout.


Syntax:

 $FILETEST ON or $FILETEST OFF

Parameters:

  • ON specifies that automatic failure checking will occur when using OPEN and CLOSE statements.
  • OFF specifies that automatic failure checking will not occur when using OPEN and CLOSE statements.

OPEN statement

Purpose: The OPEN statement opens a file, specifies a streaming mode, and associates a file handle name with the file.


Syntax:

 OPEN FileName$ FOR StreamingMode AS FileHandleName

Parameters:

  • FileName$ can be a literal or variable string containing the name of the file with an absolute or relative path.
  • StreamingMode arguments INPUT, OUTPUT, APPEND, BINARY and NEW are outlined individually below.
  • FileHandleName is used to identify the file in subsequent procedure calls, parameter arguments and other circumstances. QBASIC syle file handle names, using the #number syntax, are not supported in BCX. File handle names usually are automatically typed as a FILE handle, however, a file handle name can be explicitly created as a FILE handle. See the File Handle Names section remarks below for details.

Remarks:

Every OPEN statement must be terminated, eventually, with a CLOSE statement. See the CLOSE section below for details.

In the C translation of OPEN and CLOSE statements, BCX automatically adds code to check for the existence of the file that is being opened or closed. If the file being opened does not exist, the program will exit and a "Can't open file FileName$" statement will be sent to stdout.

CLOSE statement

Purpose: The CLOSE statement causes the file stream associated with a file handle to be flushed and the file to be closed.


Syntax 1:

 CLOSE FileHandle

Parameters:

  • FileHandle Handle to the file to be closed.

Syntax 2:

 CLOSE

Parameters:

  • None. CLOSE without an argument will close all open files.

Remarks

Specifying more than one file to be closed is not allowed.

Opening Text Files


Syntax:

 OPEN FileName$ FOR INPUT AS hFile

Streaming Mode: open text file for reading.

Parameters:

  • FileName$ Path to and name of the file to open.
  • hFile A file handle name.

Syntax:

 OPEN FileName$ FOR OUTPUT AS hFile

Streaming Mode: truncate contents of existing file to zero length or create text file for writing.

Parameters:

  • FileName$ Path to and name of the file to open.
  • hFile A file handle name.

Syntax:

 OPEN FileName$ FOR APPEND AS hFile

Streaming Mode: append; open or create text file for writing at end-of-file.

Parameters:

  • FileName$ Path to and name of the file to open.
  • hFile A file handle name.

Opening Binary Files


Syntax:

 OPEN FileName$ FOR BINARY AS hFile

Streaming Mode: open binary file for update (reading and writing).

Parameters:

  • FileName$ Path to and name of the file to open.
  • hFile A file handle name.

Syntax:

 OPEN FileName$ FOR BINARY NEW AS hFile

Streaming Mode: truncate contents of existing file to zero length or create binary file for update.

Parameters:

  • FileName$ Path to and name of the file to open.
  • hFile A file handle name.

Syntax:

 OPEN FileName$ FOR BINARY APPEND AS hFile

Streaming Mode: append; open or create binary file for update, writing at end-of-file.

Parameters:

  • FileName$ Path to and name of the file to open.
  • hFile A file handle name.

Syntax:

 OPEN FileName$ FOR BINARY INPUT AS hFile

Streaming Mode: open binary file for reading.

Parameters:

  • FileName$ Path to and name of the file to open.
  • hFile A file handle name.

Syntax:

 OPEN FileName$ FOR BINARY OUTPUT AS hFile

Streaming Mode: open binary file for update (reading and writing).

Parameters:

  • FileName$ Path to and name of the file to open.
  • hFile A file handle name.

Remarks:

Expressions such as:


 OPEN EXTRACT$(filename$,".") & ".bas" FOR INPUT AS FP1

are valid.

Opening Random Access Files


Syntax:

 OPEN fName$ FOR BINARY [NEW] AS hFile RECLEN RecordSize

Parameters:

  • fName$ Name of file to be opened.
  • NEW [OPTIONAL] Used if a new file is being created.
  • hFile Handle to the file.
  • RecordSize This can be a TYPE structure, an INTEGER variable, or an integer literal. RecordSize, optionally, can be separated from RECLEN by an = sign, for example, RECLEN = 1024.

Remarks:

If RecordSize is a TYPE structure, RECLEN will calculate automatically the size of the TYPE structure.

If RecordSize is an INTEGER variable or a literal number, that integer must specify the fixed size of the random access record.

If RecordSize is an INTEGER variable, it must be appended with % integer data type signifier.

RecordSize is calculated before the value is passed to RECLEN. The programmer is responsible for determining the fixed size of the record.

For more details see the Using Random Access Files.

File Handle Names

BCX Console Sample Programs using OPEN function.

S10.bas S103.bas S113.bas S115.bas