Topics in this section:
Filenames (just strings: splitting, ...)
Directories (on existing files: checking, globbing)
OS Specific (copy, delete, ...)
User Input (file dialogs, ...)
Some Directory and System specific functions require external libraries: either doslib by McNeel which is free and even was shipped R14, some Vital Lisp Extensions, which are faster or others. I will provide some special BINIO- Vital Lisp extensions of mine not covered by VLX-
. These should run under Visual Lisp too.
The internal functions are defined in the modules STDFILE, the file STDFILE.LSP
.
The external modules BINIO, INIFILE and REGISTRY must be loaded extra.
Filename functions: STD-FILENAME-EXTENSION
in full letters, not abbreviated.
Most of them are covered by Vital Lisp, Visual Lisp, doslib or lisputil.arx
Most of the system specific functions follow the clib names and not CL. AutoLISP is only supported on DOS and Windows, not under Mac or funny UNIX flavors anymore, which would require more platform independent path handling functions as in CL.
Simple string-handling parts only. The files need not to exist actually.
(STD-MAKE-PATHNAME list) ; strcat's pathname portions
(STD-FPSLASH fspec) ; "d:/acad" -> "d:\\acad\\"
(STD-FILENAME-SPLIT fspec) ; "d:\acad\lisp.doc" -> '("d:\acad\" "lisp" ".doc")
(STD-FILENAME-DIRECTORY fname) ; only the path, e.g. "d:\"
(STD-FILENAME-BASE fspec) ; filename only
(STD-FILENAME-EXTENSION fspec) ; only extension with dot or ""
(STD-FILENAME fspec) ; filename and extension, without path
(STD-FILEBASE fspec) ; directory and filename, without extension
(STD-FORCE-PATH path fname) ;
(STD-DEF-EXTENSION fname defext) ; default extension, if fname has extension return this else append extension
(STD-FORCE-EXTENSION fname ext) ; force extension
(STD-LONGFNAMEP fname) ; is it a long filename?
(STD-FILENAME-UPCASE fname) ; long filenames must be case-sensitive!
Dealing with existing files: checking, searching, globbing
External library functions are required: either doslib or Vital Lisp/Visual Lisp Extensions
checking:
(STD-PROBE-FILE fname) ; => truename if exists
(STD-FILE-EXIST-P fname) ; T or nil
(STD-FILE-READABLE-P fname) ; T or nil
(STD-FILE-WRITABLE-P fname) ; T or nil
(STD-FILE-DIRECTORY-P fname) ; T or nil
(STD-DOS-FILENAME fname) ; the short 8.3 name
(STD-SAME-FILES-P fname1 fname2) ; T or nil
misc:
(STD-FILENAME-MKTEMP prefix) ; not existing temp. filename
file attributes:
(STD-FILE-SYSTIME fname) ; in cdate format
(STD-FILE-MODTIME fname) ; => internal time (secs)
(STD-FILE-SIZE fname) ; => in bytes
(STD-FILE-ATTRIB fname) ; => flag
(STD-FILE-NEWER-P target deps) ; any of deps newer than target?
globbing:
(STD-DIRECTORY-FILES fspec) ; all files in dir, including dirs
(STD-GLOB-FILES fspec) ; list of files matching
(STD-GLOB-DIRS fspec) ; list of dirs matching
finding/searching:
(STD-FINDFILE fspec) ; searches in *MODULE-PATH* first, then in the acad library path
(STD-FINDFILE-PATHS fspec path-list) ; first found fspec in the given path list
(STD-FINDFILE-EXTS fspec ext-list path-list) ; first found file with the given extensions in the paths
(STD-ACAD-LIBRARY-PATHS) ; ordered string-list of the current search path
OS-Specific Highly system dependent File Manipulations (copy, rename, ...)
External library functions are required: Common are doslib or Vital Lisp/Visual Lisp Extensions or others.
Special independent functions for text files, and externally dependent functions for binary file support (only Vital Lisp/Visual Lisp or ADS/ARX modules)
(STD-FOPEN fname ch) ; instead of (open fname ch)
(STD-FCLOSE f) ; instead of (close f)
(STD-FCLOSEALL) ; on errors
(STD-CURRENT-PATH) ; "C:/ACAD/"
(STD-CURRENT-DRIVE) ; "C:"
(STD-TRUENAME fname) ; => absolute, unified path
(STD-MKDIR fname) ; create a directory
(STD-RMDIR fname) ; remove a directory
Externally dependent:
(STD-FILE-COPY from to) ;
(STD-FILE-APPEND dest source) ;
(STD-FILE-DELETE fname) ;
(STD-FILE-RENAME old new) ;
(STD-FILE-BACKUP fspec) ; saves a copy as .BAK file
(STD-GET-DRIVE-LIST) ; all logical drives as string-list:
("A" "C" "D" "E")
Text Files only: (not system dependent)
(STD-FT-COPY fn1 fn2) ; copies fn1 to fn2
(STD-FT-APPEND fn1 fn2) ; appends fn2 after fn1
(STD-FT-BACKUP fspec) ; for text files
(STD-FT-NTH-LINES fname line) ; => string, one based
(STD-FT-LINES fname from to) ; => strlist, one based
(STD-FT-INSERT fname strlst num) ; inserts strlst into text file after num lines
(STD-READ-FILE-STRINGS fname) ; reads stringlist from ASCII File
(STD-READ-FILE-LIST fname) ; reads lisp list from ASCII File
Externally dependent. Use (std-require-external 'BINIO)
The return value of binio-open
may be of any type.
The URL is http://xarch.tu-graz.ac.at/autocad/stdlib/binio.zip
Portability issues
Intel Order (low byte first) is assumed. Real numbers are intel ordered IEEE 4 byte doubles.
Note
The file object returned by BINIO-FOPEN
cannot NOT be used with plain AutoLISP functions! Only with the functions below.
(BINIO-FOPEN fname mode) ; mode: "r" "w" "rw" "a"
(BINIO-FCLOSE f)
(BINIO-FCLOSEALL) ; in case of errors
(BINIO-FSEEK f pos [start-from]) ; => long
(BINIO-FTELL f) ; => long
(BINIO-REWIND f) ; => 0 or nil
All fput functions accept either a single type or a list of those.
(BINIO-FPUTC f int|list-of-ints)
(BINIO-FPUTINT f int|list-of-ints)
(BINIO-FPUTLONG f long|list-of-longs) ;long
(BINIO-FPUTREAL f real|list-of-reals) ;as IEEE 4 byte double
(BINIO-FPUTS f str|list-of-strs) ;ASCIIZ string (0 terminated)
(BINIO-FPUTSTRING f str|list-of-strs) ;\r\n terminated
(BINIO-FGETC f) ; like read-char but #\0 too
(BINIO-FGETINT f) ; read signed short int (2 byte)
(BINIO-FGETREAL f) ; read IEEE double (4 byte)=> real
(BINIO-FGETLONG f) ; read signed long int (4 byte)
(BINIO-FGETS f) ; read ASCIIZ string (0 terminated)
(BINIO-FGETSTRING f str) ; read \r\n terminated string
INI File Handling: Possible Extension
Externally dependent. Use (std-require 'INIFILE)
(INIFILE-GET section entry filename)
(INIFILE-SET section entry string filename)
Registry Access: Possible Extension
Externally dependent. Use (std-require 'REGISTRY)
Defined only for Windows. Currently supported by Vital Lisp/Visual Lisp. For ARX code look at setreg.arx.
(REGISTRY-READ path key) ; get value
(REGISTRY-WRITE path key value) ; change value
(REGISTRY-DELETE key) ; cannot delete if subkeys
(REGISTRY-DESCENDENTS key) ; list of subkeys
(REGISTRY-VALUES key) ; list of subvalues
(REGISTRY-ACAD-PRODUCT-KEY) ; current unique R14 Acad key
Simulating some AutoCAD file dialogs, extending getfiled
, ...
(STD-GETFILEM msg def ext flag) ; get multiple files dialog
(STD-SHOWFILE fname) ; lists textfile in dialog or on console
(STD-SHOWFILE-DIALOG fname title action) ; shows textfile in a dialog.
For the directory and system functions we need external libraries that export the needed lisp functions. The problem with such libraries is that they are AutoCAD Release specific. For every different release and platform you'll need a different library.
The functions relying on external libraries are marked with "Externally dependent".
doslib by McNeel.
Doslib is a free ADS/ARX module for all versions R12+. For R14 it's even in your bonus/cadtools directory.
Vital Lisp/Visual Lisp Extensions:
You'll need a Vital Lisp/Visual Lisp Runtime Module or better Vital Lisp/Visual Lisp itself. For the runtime module only (which is free) we will have to export the lisp functions to AutoCAD, for Vital Lisp/Visual Lisp owners there are already some extensions: The built-in with VLX- prefix and my own with BINIO- prefix. (BINIO.FAS
)
Vital Lisp extension are supported by the new Visual Lisp too, because it uses the same FAS2 format.
Other functionality not covered in the yet available modules has to be written and maintained.