open
 
 
 

Opens a file for access by the AutoLISP I/O functions

(open filename mode) 

Arguments

filename

A string that specifies the name and extension of the file to be opened. If you do not specify the full path name of the file, open assumes you are referring to the AutoCAD default drawing directory.

mode

Indicates whether the file is open for reading, writing, or appending. Specify a string containing one of the following letters:

r Open for reading.

w Open for writing. If filename does not exist, a new file is created and opened. If filename already exists, its existing data is overwritten. Data passed to an open file is not actually written until the file is closed with the close function.

a Open for appending. If filename does not exist, a new file is created and opened. If filename already exists, it is opened and the pointer is positioned at the end of the existing data, so new data you write to the file is appended to the existing data.

The mode argument can be uppercase or lowercase. Note that in releases prior to AutoCAD 2000, mode had to be specified in lowercase.

Return Values

If successful, open returns a file descriptor that can be used by the other I/O functions. If mode "r" is specified and filename does not exist, open returns nil.

NoteOn DOS systems, some programs and text editors write text files with an end-of-file marker (CTRL+Z, decimal ASCII code 26) at the end of the text. When reading a text file, DOS returns an end-of-file status if a CTRL+Z marker is encountered, even if that marker is followed by more data. If you intend to use open"a" mode to append data to files produced by another program, be certain the other program does not insert CTRL+Z markers at the end of its text files.

Examples

Open an existing file:

Command: (setq a (open "c:/program files/ <AutoCAD installation directory>/help/filelist.txt" "r"))

#<file "c:/program files/ <AutoCAD installation directory>/help/filelist.txt">

The following examples issue open against files that do not exist:

Command: (setq f (open "c:\\my documents\\new.tst" "w"))

#<file "c:\\my documents\\new.tst">

Command: (setq f (open "nosuch.fil" "r"))

nil

Command: (setq f (open "logfile" "a"))

#<file "logfile">