3.01 File Handling

Overview

All input and output in LynPlex is through files. This applies when using the console or standard input/output, even though no file is specifically referenced.

File Variables

To access a file you need to provide a file variable. Initially this can be set up as a string variable containing just a file or device name. When the file is opened the variable is converted to the correct format of file variable.

File Names

A file name is anything that is valid for the file system in use.

In Windows this will normally be in the form:

C:\mydata\myfile.txt

for an absolute file reference, or

myfile.text

for a file in the current directory.

File System Operations

Files and directories may be accessed through a FILE variable.

Device Names

Device names that are recognised by the operating system, and where access is allowed, may also be used.

For example:

COM1:[speed]
Serial port 1
COM2:[speed]
Serial port 2
SOCL:server:port
Socket client. Actually a telnet client.

Opening a File

To access a file it must be opened with the OPEN command.

If a GET or PUT command is directed to a file that is not yet opened, it will be opened for input or output respectively at that time. For any other type of access the file must be opened explicitly.

Closing a File

When a file is no longer needed it should be closed with the CLOSE command.

If a file is still open at the end of the program it will be closed automatically.

Commands

OPEN

Function:

Makes a file or device available for sequential input or sequential output.

Syntax:

OPEN file [FOR {INPUT|OUTPUT|APPEND|UPDATE}]

where:

file
A file variable or a string variable that contains the name of a file that follows the host system file naming conventions. A string variable will be converted to a file variable by OPEN.
INPUT
Stream input
OUTPUT
Stream output
APPEND
Stream output, beginning at current EOF
UPDATE
Both input and output. Access may be stream or direct.

The files are always opened as shared.

Example:

file = "myfile.txt"
open file for input
close file
...
file = "COM1:"
open file for update
close file

CLOSE

Function:

Close a file or device

Syntax:

CLOSE file

where:

file
a file variable that is currently open.

lynplex/lp0301.txt · Last modified: 2011/11/06 19:21 (external edit)