FILE_OPEN
Syntax |
FILE_OPEN ([#ch,] device [,{mode% | ChID}]) |
Location |
BTool |
FILE_OPEN is a function which will open any device (default data directory supported for files) for all kinds of tasks. If a channel number #ch is not supplied, FILE_OPEN will choose the channel number on its own by searching for the next free channel number and returning it.
FILE_OPEN returns the channel number if it was not specified or otherwise zero. In case of failure it will return a (negative) error code. If error -4 (‘out of range’) is returned when a channel number has not been supplied, this indicates that the channel table of a compiled job is full.
The third parameter can be either the open mode or the channel ID of an un-named pipe.
The open mode (default 0) is:
0 (old exclusive) - open an existing file to read and write.
1 (old shared) - open an existing file to read only.
2 (new exclusive) - create a new file if it does not exist.
3 (new overwrite) - create a new file, whether or not it exists.
4 (dir open) - open a directory to read only.
If the third parameter is the channel ID of an open input pipe, then FILE_OPEN will create an output pipe linked to that channel.
Example
Count additional keywords:
100 ch1=FILE_OPEN(pipe_10000)
110 ch2=FILE_OPEN(pipe_,CHANID(#ch1))
120 EXTRAS#ch1
130 FOR count=1 TO 1E6
140 IF IO_PEND%(#ch2) THEN EXIT
150 INPUT#ch2,keyword$
160 AT 0,0: PRINT count
170 END FOR count
180 CLOSE#ch1,#ch2
CROSS-REFERENCE
FILE_OPEN combines OPEN, OPEN_IN, OPEN_NEW, OPEN_OVER, OPEN_DIR, FOPEN, FOP_IN, FOP_OVER, FOP_NEW, FOP_DIR, TTEOPEN and TCONNECT. See also CHANID and ERNUM.