BCX File Management Functions

APPEXENAME$ function
APPEXEPATH$ function
BCXPATH$ function
BFF$ function
CLOSE statement
COMBOBOXLOADFILE statement
COPYFILE statement
EOF statement
EXIST function
FILELOCKED function
FINDFIRST$ function
FINDNEXT$ function
FREEFILE function
GETFILENAME$ function
GETATTR statement
KILL statement
LISTBOXLOADFILE statement
LOADFILE$ function
LOC function
LOF function
LOOKAHEAD$ function
OPEN statement
PELLESPATH$ function
REC function
RECCOUNT function
RECORD function
RECLEN statement
RENAME statement
REWIND statement
SETATTR statement

FILELOCKED function

Purpose:

FILELOCKED determines whether or not a file can be opened.

Syntax:

RetVal = FILELOCKED(FileName AS STRING)

Parameters:

  • Data type: INTEGER
    RetVal If the file cannot be opened, 1, if it can be opened, 0.
  • Data type: STRING
    FileName The name of a file.

$FILETEST ON ... $FILETEST 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 Automatic failure checking will occur when using OPEN and CLOSE statements.
  • OFF 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.

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

Syntax:

OPEN FileName FOR StreamingMode AS hFile

Parameters:

  • Data type: STRING
    FileName A literal or variable string containing the name of the file with an absolute or relative path.
  • Data type: Argument
    StreamingMode INPUT, OUTPUT, APPEND, BINARY and NEW arguments are outlined, individually, below.
  • Data type: FILE PTR
    hFile A file handle name that identifies the file in subsequent procedure calls, parameter arguments and other circumstances.
    See the File Handle Names section remarks below for details.

Remarks:

👉 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 hFile

Parameters:

  • Data type: FILE PTR
    hFile The handle of the file to be closed.

Syntax 2:

CLOSE

Parameters:

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

Remarks:

👉 The CLOSE statement allows multiple file handles on one line. For example,

CLOSE #1, #2, FP3, MyDocHandle

Opening Text Files

OPEN FileName FOR INPUT statement

Purpose:

Streaming Mode: open text file for reading.

Syntax:

OPEN FileName FOR INPUT AS hFile

Parameters:

OPEN FileName FOR OUTPUT statement

Purpose:

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

Syntax:

OPEN FileName FOR OUTPUT AS hFile

Parameters:

OPEN FileName FOR APPEND statement

Purpose:

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

Syntax:

OPEN FileName FOR APPEND AS hFile

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

Parameters:

Opening Binary Files

OPEN FileName FOR BINARY statement

Purpose:

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

Syntax:

OPEN FileName FOR BINARY AS hFile

Parameters:

OPEN FileName FOR BINARY NEW statement

Purpose:

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

Syntax:

OPEN FileName FOR BINARY NEW AS hFile

Parameters:

OPEN FileName FOR BINARY APPEND statement

Purpose:

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

Syntax:

OPEN FileName FOR BINARY APPEND AS hFile

Parameters:

OPEN FileName FOR BINARY INPUT statement

Purpose:

Streaming Mode: open binary file for reading.

Syntax:

OPEN FileName FOR BINARY INPUT AS hFile

Parameters:

OPEN FileName FOR BINARY OUTPUT statement

Purpose:

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

Syntax:

OPEN FileName FOR BINARY OUTPUT AS hFile

Parameters:

Remarks:

Expressions such as:

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

are valid.

File Handle Names

BCX Console Sample Programs using the OPEN function.