USFile.Open

Previous Next

Opens a file for reading, writing, or appending. Assigns an alias to the opened file. This alias can then be used in successive calls to the USFile component. The alias can also be used by the XML.Export method.

If the file is successfully opened, the alias is returned. If a failure occurs, an error message is generated.

When you have finished reading from or writing to a file that was successfully opened, close it by using the USFile.Close method.

Syntax

INVOKE USFile.Open WITH

SELECT     alias

,          filename

,          mode        "Mode"

,          encoding    Encoding

 

mode      :=  { APPEND | READ | WRITE }

encoding  :=  UTF-8 | ASCII | UTF16LE }

 

The required and case-insensitive alias is the alias to be assigned to the successfully opened text file. This alias can be used as a file handle in subsequent calls to USFile.

The required filename specifies the folderpath and filename of the text file to be opened. This name is allowed to contain environment variables.

The optional mode is the mode in which the file is opened. Possible values are READ, WRITE and the default APPEND. Use READ to read from the opened file. Use APPEND or WRITE to write to the opened file. If you use WRITE, the existing contents of the file (if any) are lost.

CAUTION: The column alias "Mode" must be surrounded by double quotes if "Mode" is a SQL keyword on your database platform. Otherwise, double quotes around column aliases are optional.

The optional encoding is effective only when mode is APPEND or WRITE. If mode is READ, the existing encoding of the opened file applies. Possible values for encoding are: UTF-8 (the default), ASCII, and UTF16LE (= UTF-16 Little Endian).

Example

INVOKE USFile.Open WITH

SELECT    'ToursFile'

,         '%TEMP%\MyToursFile.txt'

,         'WRITE'   "Mode"

,         'ASCII'   Encoding

 

 

collapseThe USFile prefix
collapseRepeated calls to USFile.Open

 

 

See Also

USFile.Close

USFile Internal Component