WPerciful 发表于 2022-7-5 23:25:18

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?

MSasu 发表于 2022-7-5 23:36:05

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)))

Tharwat 发表于 2022-7-5 23:42:31

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))

WPerciful 发表于 2022-7-5 23:49:08

Tharwat,
 
I sometimes get this error using your code:
error: file pattern specification is too long
 
Thank you MSasu.
 
Thank you Tharwat.

Tharwat 发表于 2022-7-5 23:57:30

How did you call the function ?

WPerciful 发表于 2022-7-6 00:05:50

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.

Tharwat 发表于 2022-7-6 00:17:42

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 .

WPerciful 发表于 2022-7-6 00:24:29

Ok, thank you!

Tharwat 发表于 2022-7-6 00:32:47

 
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]
查看完整版本: DWGs in folder & sub-folders