Skip to content

Opening Sequential I/O Files

DataFlex can read data from, and write data to, up to ten sequential I/O files simultaneously. Before you can read or write sequential data, you must first open the file. The syntax for opening a file for input (reading) is:

direct_input  [channel {channel-num.}] {file-name}

The syntax for opening a file for output (writing) is:

direct_output [channel {channel-num.}] {file-name}

Where:

  • {channel-num.} is the assigned channel for the file that is being opened.
  • {file-name} is the name and path of the file that is being opened. {file-name} can be a string token, string variable, or a string expression.

Examples of Opening a File for Sequential I/O

direct_input  "c:\myDocs\Readme.txt"
direct_output sErrorLog

Assigning an Explicit I/O Channel

Whenever a file is opened for I/O, it is assigned an I/O channel. DataFlex supports up to ten channels for simultaneous sequential file I/O. The channels are numbered 0..9.

The default channel for input is channel 0; the default channel for output is channel 1.

The channel that you assign to a file when it is opened for sequential I/O must be unused. When you close a file for sequential I/O, the channel that was assigned to it becomes available for reuse.

Examples of Opening a File for Sequential I/O with Explicit Channel Assignment

direct_output channel 3  "c:\myDocs\Readme.txt"
direct_output channel iOutChannel  "c:\autoexec.bat"

Testing for Valid Input Files

If the file named in a direct_input statement cannot be opened, then the Boolean expression seqeof returns True. The following example demonstrates how you can test for a valid input file name.

direct_input  sActivityLog
If (seqeof) Showln "Error: can't open " sActivityLog