View Full Version : List dwg's from all subdirectories.
jsowinski
2007-10-18, 08:14 PM
Hi everyone-
Is there any lisp code (or any other code) in AutoCAD that will list all drawings within every subdirectory of a given path? I'm trying to generate a list box in a dcl with block names from our library. Unfortunately our library contains many subdirectories under one main heading and I have not had any luck digging deep into the search path. I appreciate any help. Thanks.
Jim
T.Willey
2007-10-18, 09:43 PM
(defun GrabAllFiles (Path FileExt / tempPath FileList)
; [Path] is the path to search it, and all it's sub-directory
; [FileExt] is the extenstion (with the period) of the type of files to look for.
; Example (GrabAllFiles "c:\\" ".dwg")
(setq Path
(if (= (substr Path (strlen Path)) "\\")
Path
(strcat Path "\\")
)
)
(foreach file (vl-directory-files Path)
(setq tempPath (strcat Path file))
(if
(not
(or
(= file ".")
(= file "..")
)
)
(if (vl-file-directory-p tempPath)
(setq FileList (append FileList (GrabAllFiles tempPath FileExt)))
(if (= (strcase FileExt) (strcase (vl-filename-extension tempPath)))
(setq FileList (cons tempPath FileList))
)
)
)
)
FileList
)
jsowinski
2007-10-19, 03:39 PM
Tim-
This is sweet routine! Thanks! I was wondering when it generates the list of drawings if it could show just the drawing names instead of the entire path and name. Thanks again.
Jim
T.Willey
2007-10-19, 05:00 PM
Tim-
This is sweet routine! Thanks!
You're welcome Jim.
I was wondering when it generates the list of drawings if it could show just the drawing names instead of the entire path and name. Thanks again.
Jim
Sure, all you need to do is change this line
(setq FileList (cons tempPath FileList))
to
(setq FileList (cons file FileList))
jsowinski
2007-10-22, 03:34 PM
Tim-
You are good at what you do! Thanks again for your help.
Jim
ElpanovEvgeniy
2007-10-23, 11:16 AM
My programs... :)
(defun GetFolders (p)
;; By ElpanovEvgeniy
;; (GetFolders '("C:\\Program Files\\AutoCAD 2004\\Sample"))
;|
Function of search of all folders,
inside of the root folders specified in the list.
Arguments:
P - the list of root folders.
For example '("C:\\Program Files") or ' ("C:" "D:" "E:")
To cause
(GetFolders '("C:\\Program Files\\AutoCAD 2004\\Sample"))
Returns the list of folders, including specified in the list of search.
' ("C:\\Program Files\\AutoCAD 2004\\Sample"
"C:\\Program Files\\AutoCAD 2004\\Sample\\ActiveX"
"C:\\Program Files\\AutoCAD 2004\\Sample\\Database Connectivity"
"C:\\Program Files\\AutoCAD 2004\\Sample\\DesignCenter"
"C:\\Program Files\\AutoCAD 2004\\Sample\\VBA"
"C:\\Program Files\\AutoCAD 2004\\Sample\\VisualLISP"
"C:\\Program Files\\AutoCAD 2004\\Sample\\ActiveX\\ExtAttr"
"C:\\Program Files\\AutoCAD 2004\\Sample\\ActiveX\\ExternalCall"
"C:\\Program Files\\AutoCAD 2004\\Sample\\Database Connectivity\\CAO"
"C:\\Program Files\\AutoCAD 2004\\Sample\\VBA\\VBAIDEMenu"
"C:\\Program Files\\AutoCAD 2004\\Sample\\VisualLISP\\activex"
"C:\\Program Files\\AutoCAD 2004\\Sample\\VisualLISP\\External"
"C:\\Program Files\\AutoCAD 2004\\Sample\\VisualLISP\\mdi-vlx"
"C:\\Program Files\\AutoCAD 2004\\Sample\\VisualLISP\\reactors"
)
|;
(if p
(append
p
(GetFolders
(apply
(function append)
(mapcar
(function (lambda (b)
(mapcar (function (lambda (a) (strcat b "\\" a)))
(vl-remove ".." (vl-remove "." (vl-directory-files b nil-1)))
) ;_ mapcar
) ;_ lambda
) ;_ function
p
) ;_ mapcar
) ;_ apply
) ;_ GetFolders
) ;_ append
) ;_ if
) ;_ defun
(defun GetFile (f p)
;; By ElpanovEvgeniy
;; (getfile "acad*.lsp" "C:\\Program Files")
;|
Function of search of a file or files
in the specified folder and all enclosed folders
The file is set by a name or a mask
Arguments:
P - an initial way of search,
For example "C:" or "C:\\Program Files"
F - the name of a file,
Use WCMATCH symbols is possible.
For example
"*.dwg" - will find all dwg-files
Or "acad*.lsp"
To cause
(getfile "acad*.lsp" "C:\\Program Files\\AutoCAD 2004")
Returns the list of files with full by up to them and the name without a mask.
' ("C:\\Program Files\\AutoCAD 2004\\Express\\acadinfo.lsp"
"C:\\Program Files\\AutoCAD 2004\\Support\\acad2004.lsp"
"C:\\Program Files\\AutoCAD 2004\\Support\\acad2004doc.lsp"
"C:\\Program Files\\AutoCAD 2004\\Support\\acadinfo.lsp"
)
|;
(apply (function append)
(cons (if (vl-directory-files p f)
(mapcar (function (lambda (x) (strcat p "\\" x))) (vl-directory-files p f))
) ; _ if
(mapcar (function (lambda (x) (GetFile f (strcat p "\\" x))))
(vl-remove ".." (vl-remove "." (vl-directory-files p nil-1)))
) ;_ mapcar
) ;_ cons
) ;_ apply
) ;_ defun
(defun GetFirstFile (f p)
;; By ElpanovEvgeniy
;; (GetFirstFile "a?ad.exe" '("C:\\Program Files"))
;|
Function of search of a file inside of the root folders specified in the list
And all enclosed folders
Search stops on the first specified file
The file is set by a name or a mask
In comparison with function GetFile works more quickly,
Since interrupts search, after a finding of a file.
It is recommended for search of files with the unique name.
Arguments:
P - the list of root folders.
For example '("C:\\Program Files") or '("C:" "D:" "E:")
F - the name of a file,
Use WCMATCH symbols is possible.
For example:
"a?ad.exe "
To cause:
(GetFirstFile "a?ad.exe" '("C:\\Program Files"))
Returns a line - a full way to a file with the full name.
"C:\\Program Files\\AutoCAD 2004\\acad.exe"
|;
(cond
((not p) nil)
((vl-directory-files (car p) f)
(strcat (car p) "\\" (car (vl-directory-files (car p) f)))
)
((GetFirstFile
f
(append (mapcar (function (lambda (x) (strcat (car p) "\\" x)))
(vl-remove ".." (vl-remove "." (vl-directory-files (car p) nil-1)))
) ; _ mapcar
(cdr p)
) ;_ append
) ;_ GetFirstFile
)
) ;_ cond
) ;_ defun
jsowinski
2007-10-26, 08:06 PM
Evgeniy-
I'll have to give your routine a try. Thanks.
Jim
vBulletin® v3.6.7, Copyright ©2000-2009, Jelsoft Enterprises Ltd.