WPerciful Posted March 11, 2014 Posted March 11, 2014 (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? Quote
MSasu Posted March 11, 2014 Posted March 11, 2014 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)) ) Quote
Tharwat Posted March 11, 2014 Posted March 11, 2014 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) ) Quote
WPerciful Posted March 11, 2014 Author Posted March 11, 2014 Tharwat, I sometimes get this error using your code: error: file pattern specification is too long Thank you MSasu. Thank you Tharwat. Quote
WPerciful Posted March 11, 2014 Author Posted March 11, 2014 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. Quote
Tharwat Posted March 11, 2014 Posted March 11, 2014 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 . Quote
Tharwat Posted March 12, 2014 Posted March 12, 2014 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 . Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.