0 Members and 1 Guest are viewing this topic.
(defun load-lsp () (foreach file (vl-directory-files "D:/acad_apps/" "*.lsp" 1) (load file (strcat file " did not load")) ) )
Didn't MP post something like that a year or so ago?
;|=======================================================================================* Function z-files-in-directory returns the list of files being in the set directory* The author: Zuenko Vitaly (ZZZ)* http://www.autocad.ru/cgi-bin/f1/board.cgi?t=19612AN&page=2* Arguments:* directory Path to a folder for example "D:\\My documents\\ZEF\\Lisp"* pattern pattern for example "*.lsp" or list '("*.dwg" "*.dxf")* nested To search in the sub folders: t (yes) or nil (no)* Usage:(z-files-in-directory "D:\\My documents\\ZEF\\Lisp" "*.lsp" t)(z-files-in-directory "D:\\My documents\\ZEF\\Lisp" '("*.lsp" "*.fas") t)=======================================================================================|;(defun z-files-in-directory (directory pattern nested /) (if (not (listp pattern)) (setq pattern (list pattern)) ) ;_ if (if nested (apply 'append (append (mapcar '(lambda (_pattern) (mapcar '(lambda (f) (strcat directory "\\" f)) (vl-directory-files directory _pattern 1) ) ;_ list ) ;_ lambda pattern ) ;_ mapcar (mapcar '(lambda (d) (z-files-in-directory (strcat directory "\\" d) pattern nested ) ;_ z-files-in-directory ) ;_ lambda (vl-remove "." (vl-remove ".." (vl-directory-files directory nil -1)) ) ;_ vl-remove ) ;_ mapcar ) ;_ append ) ;_ append (apply 'append (mapcar '(lambda (_pattern) (mapcar '(lambda (f) (strcat directory "\\" f)) (vl-directory-files directory _pattern 1) ) ;_ list ) ;_ lambda pattern ) ;_ mapcar ) ;_ apply ) ;_ if ) ;_ defun
;http://discussion.autodesk.com(defun BrowseFolder ( / ShlObj Folder FldObj OutVal) (vl-load-com) (setq ShlObj (vla-getInterfaceObject (vlax-get-acad-object) "Shell.Application" ) Folder (vlax-invoke-method ShlObj 'BrowseForFolder 0 "" 0) ) (vlax-release-object ShlObj) (if Folder (progn (setq FldObj (vlax-get-property Folder 'Self) OutVal (vlax-get-property FldObj 'Path) ) (vlax-release-object Folder) (vlax-release-object FldObj) OutVal ) )); Check and set of a variable *z_root_dir* - a path to a folder of automatic loading(if (or (not (getenv "*z_root_dir*")) (= (getenv "*z_root_dir*") "") ) ;_ or (setenv "*z_root_dir*" (BrowseFolder)));Loading of library (mapcar 'load (z-files-in-directory (getenv "*z_root_dir*") '("*.lsp" "*.fas" "*.vlx") t) ) ;_ mapcar
( (lambda ( path ) ;; a quick demonstration of how to load all the lisp files in a dir. (mapcar ;; itterate thru a list of files in directory (function (lambda ( x ) (cond ;; determine if the file is of type... ((or (wcmatch x "*.lsp") (wcmatch x "*.vlx") (wcmatch x "*.fas")) ;; if it is, load it (load (strcat path x)) ) ) ; cond ) ; lambda ) ; function ( (lambda ( ) ;; build a list of files in the given path (if (null path) ;; just in case you didnt specify a path nil (vl-directory-files path "*.*" 1))) ) ) ; mapcar ) ; lambda "c:\\")
If MP did I could not find it.I did find this vl-directory-files + MP but not the same thing.
(defun rjp-loadlisp (/ lst) (setq lst (vl-directory-files "C:\\Program Files\\AutoCAD Tools\\Lisp" "*.lsp" 1 ) lst (mapcar 'vl-filename-base lst) ) (foreach x lst (vl-catch-all-apply 'autoload (list x (list x))) ))(rjp-loadlisp)
; lap is stand for Loading Alls Program; Design by : Adesu <Ade Suharna>; Email : mteybid@yuasabattery.co.id; Homepage : http://www.yuasa-battery.co.id; Create : 20 July 2006; Program no.: 0383/07/2006; Edit by : Adesu 04/09/2006 1).; 13/09/2006 2).; 13/10/2006 3).; 07/12/2006 4).; 19/12/2006 5).(defun c:lap (/ all_file_name file_folder finish len load_name start start_hour start_minute start_second) (setq start (rtos (getvar "CDATE") 2 18)) ; 5). (setq start_hour (atof (substr start 10 2))) ; 5). (setq start_minute (atof (substr start 12 2))) ; 5). (setq start_second (atof (substr start 14 4))) ; 5). (vl-load-com) (setq file_folder "D:/YBI/Program/AutoLisp/Lisp program/My Alls Program") (setq all_file_name (cddr (vl-directory-files file_folder))) (setq len (length all_file_name)) ; 4). (setq all_file_name (mapcar '(lambda (x)(nth x all_file_name)) (vl-sort-i all_file_name '<))) (foreach x all_file_name (setq load_name (strcat file_folder "/" x)) (load load_name) ) ; foreach (princ "\n*******loading alls program have been successful*******") ; 1). (princ "\n") ; 4). (princ (strcat "\n*** Total program Autolisp is = " (itoa len) " Pcs ***")) ; 4). (princ "\n") ; 5). (setq finish (rtos (getvar "CDATE") 2 18)) ; 5). (setq finish_hour (atof (substr finish 10 2))) ; 5). (setq finish_minute (atof (substr finish 12 2))) ; 5). (setq finish_second (atof (substr finish 14 5))) ; 5). (setq duration_hour (- finish_hour start_hour)) ; 5). (setq duration_minute (abs (- finish_minute start_minute))) ; 5). (setq duration_second (abs (/ (- finish_second start_second) 100))) ; 5). (gc) (princ (strcat "\nDURATION TIME RECORDED AS" "\nHour = " (rtos duration_hour 2 0)(chr 176) "\nMinute = " (rtos duration_minute 2 0)(chr 180) "\nSecond = " (rtos duration_second 2 0)(chr 168))) ; 4). (alert "\n******* LOADING ALLS PROGRAM HAS BEEN SUCCESSFUL *******") ; 2). 3). (princ) ) ; defun
I currently use 3 different functions to load all the files in a certain directory, I thought it would be fun to write a function to load any .lsp, .fas or .vls files found in a directory. Here is a sample of what I use for .lsp.Code: [Select](defun load-lsp () (foreach file (vl-directory-files "D:/acad_apps/" "*.lsp" 1) (load file (strcat file " did not load")) ) )This thread gave me the idea
(defun load-lsp (path) (foreach f (apply (function append) (mapcar (function (lambda (x) (vl-directory-files path x 1) ) ;_ lambda ) ;_ function '("*.LSP" "*.FAS" "*.VLX") ) ;_ mapcar ) ;_ apply (load (strcat path "\\" f) (strcat path "\\" f " did not load")) ) ;_ foreach) ;_ defun(load-lsp "D:\Work")