Jump to content

DWGs in folder & sub-folders


WPerciful

Recommended Posts

(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?

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

Tharwat,

 

I sometimes get this error using your code:

error: file pattern specification is too long

 

Thank you MSasu.

 

Thank you Tharwat.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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 .

Link to comment
Share on other sites

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 .

Link to comment
Share on other sites

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...