(setq fw (open "file1.txt" "w")) opens the file named FILE1.TXT for writing and assigns a file descriptor to variable fw. The "w" must be lower case. When opening a file for writing, a new file is created. If an old file by the same name exists, it is overwritten.
(setq fa (open "file2.txt" "a")) opens the file named FILE2.TXT to be appended assuming the file already exists. If it does not already exist, it is created. The "a" must be lower case.
(setq fr (open "file3.txt" "r")) opens the file named FILE3.TXT for reading and assigns a file descriptor to variable fr. The "r" must be lower case. When opening a file for reading, the file must already exist or the open function returns nil.
(setq f7 (open "a:\\stock\\file7.txt" "w")) opens file FILE7.TXT
in folder A:\STOCK for writing. (A single forward slash can be used
in place of the double backslash. Thus, the previous file name is
equivalent to "a:/stock/file7.txt")
(close f4) closes the file identified by file descriptor f4 and returns nil.
The argument must be a variable holding the descriptor of a file opened
with the open function. If the file was opened for writing, any contents
in the file buffer not yet sent to disk are sent.
(read-line f9) reads one line from the file identified by the file descriptor f9 (which was previously opened for reading). If there are no more lines to be read, read-line returns nil
(read-line) reads a line from the keyboard buffer. If there are no lines in the buffer, it waits.
To reset the file pointer to the first string, close then re-open the file for reading.
(write-line "Abraham Lincoln") writes Abraham Lincoln on the screen and returns "Abraham Lincoln"
(write-line "Abraham Lincoln" f8) writes Abraham Lincoln to the
file identified by file descriptor f8 (which was previously opened for
writing) and returns "Abraham Lincoln"
(read-char f7) reads one character from the file identified by the file descriptor f7 (which was previously opened for reading)
(read-char) reads one character from the keyboard buffer. If there
are no characters in the buffer, it waits.
(write-char 65) writes "A" to screen and returns 65
(write-char 65 f8) writes "A" to the file identified by file descriptor f8 (which was previously opened for writing) and returns 65
If no path is supplied, AutoLISP will look in the AutoCAD search path for the file. If a path is supplied, only that path is searched for the file. The AutoCAD search path includes the current folder, the folder holding the current drawing file, plus the folders listed in AutoCAD under "Preferences," under the "Files" tab, under "Support file search path."
If the specified file is found, a string containing the file's full name (including path) is returned. Otherwise nil is returned. For example, if the file Pen.txt exists only in the \Work folder (which is the current folder and/or the folder holding the current drawing), then
(findfile "Pen.txt") returns "C:\\Work\\Pen.txt"
(findfile "\\Alpha\\Pen.txt") returns nil
Remember, in a string describing a file path, the double backslash equals
a single forward slash.
(getfiled "Select block to insert" "c:\\blocklib\\standard.dwg" "dwg" 0) displays a file dialog box with the title "Select block to insert" at the top, with the c:\blocklib folder opened and "standard.dwg" shown in the file name box as the the default file, and with only "dwg" files listed. The fourth argument (0) allows user to select an existing file rather than create a file.
Other settings for the fourth argument:
1 = Create a new file
2 = Disable the "Type it" button
4 = Let user enter any file extension even if different than that indicated in the third argument
8 = Return only file name rather than full path to file (unless other files by same name exist in other folders
These can be combined in bitwise fashion. For example, 5 = (1 + 4) would create a new file and let the user enter any extension.