open
(open fileName openMode
[encoding])
This function opens a (text or binary)
file fileName for read and/or write access as specified by
openMode.
Arguments
|
fileName string, name of the file to be opened, can contain a
fully specified path; if no path is specified, the standard folder
search sequence is used as with (findfile);
openMode string, specifies whether opening for read/write is
requested :
"r" opening for read
operations
"w" opening for write operations, file
content is automatically cleared, file is created if not existing
yet
"a" opening for append, file content is
not cleared, file is created if not existing yet
BricsCAD supports to open a file in "binary"
mode :
"rb"
"wb"
"ab"
modes can be used to specify the "binary" mode
: characters are not translated, but written "as is"
BricsCAD Lisp supports extended
openMode settings,
please see read + write text files
encoding :
(optional) string, specifies UTF-8 with or without BOM; allowed
"utf8" and "utf8-bom";
if using UTF-8 format, it is *strongly*
suggested to use "UTF-8 with BOM" (UTF-8 without BOM can not be
distinguished from normal ANSII !)
|
Return
|
"file descriptor" (value of
type FILE) if opening was successful, NIL if opening failed
|
Example
|
(open "on_doc_load.lsp" "r")
#<FILE : nnnnnn>
(open "ThisFileDoesNotExist.txt" "r")
NIL
(open "ThisFileDoesNotExist.txt" "w")
#<FILE : nnnnnn>
(open "ThisFileDoesNotExist.txt" "r")
#<FILE : nnnnnn>
|
Remarks
|
1. the new
encoding option,
as introduced by AutoCAD 2021, is supported in BricsCAD V21 and
higher;
2. see
(findfile) function, and SRCHPATH / ACADPREFIX settings;
for some BricsCAD-specific and
backward-compatible extension, please see detailed informations for
opening non-ASCII/ANSI files in Extended AutoLISP Functions
3. BricsCAD Lisp
supports extended openMode
settings, please see read + write text files
|