DWGs in folder & sub-folders
(vl-directory-files "C:\\Users\\wpe\\Documents" "*.dwg")Returns a list of DWGs in a folder, but is there to have it return a list of DWGs in the folder and sub-folders? For one level of sub-folders:
(foreach subFolder (vl-remove "." (vl-remove ".." (vl-directory-files "C:\\Users\\wpe\\Documents" nil -1)))(print (vl-directory-files (strcat "C:\\Users\\wpe\\Documents\\" subFolder) "*.DWG" 1))) Try this recursive code
(defun PullDwgs (dir / l lst f dwgs) ;; Tharwat 11. Mar. 2014 ;; (if (setq l (vl-directory-files dir nil 0)) (progn (setq lst (vl-directory-files dir nil -1) l (vl-remove-if '(lambda (u) (or (eq u ".") (eq u ".."))) l) f (vl-remove-if-not '(lambda (u) (wcmatch u "*.dwg")) l) dwgs (cons f dwgs) ) (if lst (foreach x (vl-remove-if '(lambda (u) (or (eq u ".") (eq u ".."))) lst ) (setq dwgs (cons (PullDwgs (setq dir (strcat dir "\\" x))) dwgs)) ) ) )) (vl-remove nil dwgs)) Tharwat,
I sometimes get this error using your code:
error: file pattern specification is too long
Thank you MSasu.
Thank you Tharwat. How did you call the function ? This one gets the error:
(pulldwgs"O:\\Project 482 - Sterling Centennial Gas Plant")
This code works
(pulldwgs"O:\\Project 482 - Sterling Centennial Gas Plant\\Design - Project 482 Sterling Centennial Gas Plant\\Piping Mechanical")
I was trying to use this to allow me to batch update a whole project folder.You routine allows me to do a department at a time, but now the root folder. I can't be sure if the path of the first folder is correct since it worked on the second one , check the path once again .
I have nothing to add since that it is a matter of correct path . Ok, thank you!
I just tried the code in the office and it works as expected .
Please try again and if you can post an image of your folder and the way you tried the code , it would be great .
Good luck .
页:
[1]