#1
|
|||
|
|||
Create a list of files in LISP
This is a LISP question.
I have a dialog menu in Modeling that creates a list of all package files in a working directory and allows the user to load it along with the corresponding annotations file. It works fine except when I have a file with the file extension in upper case (e.g. PKG), the entry does not appear on the list. In the code the relevant LISP commands are file-namestring and directory. I am not fluent enough in LISP to come up with a solution. Is there a way to include the upper case file extensions ? (e.g 12-12345.PKG) here's the code PHP Code:
Any help is appreciated. Dave Nowak |
#2
|
||||
|
||||
Re: Create a list of files in LISP
append, as well as nconc does concatenate 2 lists to have one at the end.
Code:
(let ((pkg_files (append (mapcar 'file-namestring (directory "F:/Me10/*.pkg")) (mapcar 'file-namestring (directory "F:/Me10/*.PKG")))))) Code:
(let ((pkg_files (mapcar 'file-namestring (append (directory "F:/Me10/*.pkg") (directory "F:/Me10/*.PKG"))))))
__________________
Last edited by Wolfgang; 02-09-2011 at 10:26 AM. Reason: fixed the wrong brackets as mentioned in next post.. |
#3
|
|||
|
|||
Re: Create a list of files in LISP
Thanks for the input Wolfgang
Now I do have all the package files in a list, both of your examples work. Just a slight change to the second example where I move the parentheses for the append. PHP Code:
e.g. Instead of this list 123.pkg 246.pkg 567.pkg 321.PKG 456.PKG I would like this list 123.pkg 246.pkg 321.PKG 456.PKG 567.pkg It seems there is a sort command in LISP but I can not get it to go. Again any help is appreciated Dave Nowak |
#4
|
||||
|
||||
Re: Create a list of files in LISP
Quote:
Quote:
Code:
(sort the-list #'the-sort-function) ;; returns the sorted list example: Code:
(sort '(5 9 78 6 7 8 9 3 8 4 17) #'<) Code:
(let ((pkg_files (sort (mapcar 'file-namestring (append (directory "F:/Me10/*.pkg") (directory "F:/Me10/*.PKG"))) #'string< ))))
__________________
Last edited by Wolfgang; 02-09-2011 at 10:41 AM. |
#5
|
|||
|
|||
Re: Create a list of files in LISP
Thanks Wolfgang
The sort works, below is the complete code for anyone interested. Code:
;*********************************************************************** ;DIALOG, LOAD PACKAGE FILE AND ANNOTATION FROM WORK AREA ;*********************************************************************** (oli::sd-defdialog 'sto_dia_load_files_from_work_area :dialog-title "Load From Work Area" :toolbox-button nil :variables '((work_area_file :title "F:\\Me10\\*.pkg" :range ("dummy") :initial-value (let ((pkg_files (sort (mapcar 'file-namestring (append (directory "F:/Me10/*.PKG") (directory "F:/Me10/*.pkg"))) #'string<))) (oli::sd-set-range 'work_area_file pkg_files) ; (car pkg_files) ;select first in list ) :after-input (if (and (oli::sd-inq-file-status (format nil "F:\\Me10\\~a.mi" (subseq work_area_file 0 (- (length work_area_file) 4))) :existence) (oli::sd-module-active-p "ANNOTATION")) (progn (oli::sd-set-variable-status 'load_mi :enable t) (oli::sd-set-variable-status 'load_mi :value t) ) (oli::sd-set-variable-status 'load_mi :enable nil) ) ) ;; end dir-range (load_mi :value-type :boolean :title " Load MI" :initial-value nil ) ) ; end variables :after-initialization '(if (oli::sd-module-active-p "ANNOTATION") (oli::sd-set-variable-status 'load_mi :enable t) (oli::sd-set-variable-status 'load_mi :enable nil) ) :ok-action '(sto_fun_load_files_from_work_area work_area_file load_mi) ) ; end dialog (defun sto_fun_load_files_from_work_area (work_area_file load_mi) ;reset session (uic_reset_session :yes) (if (oli::sd-module-active-p "ANNOTATION") (progn (oli::sd-switch-application "Annotation") (am_drawing_delete :dwg) (oli::sd-maximize-vp "Annotation") ) ) (load_package (format nil "F:\\Me10\\~a" work_area_file)) (if (and load_mi (oli::sd-module-active-p "ANNOTATION")) (progn (am_load_drawing :filename (format nil "F:\\Me10\\~a.mi" (subseq work_area_file 0 (- (length work_area_file) 4)))) ) ) (oli::sd-switch-application "SolidDesigner") ) |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
|
|