乐筑天下

搜索
欢迎各位开发者和用户入驻本平台 尊重版权,从我做起,拒绝盗版,拒绝倒卖 签到、发布资源、邀请好友注册,可以获得银币 请注意保管好自己的密码,避免账户资金被盗
查看: 83|回复: 8

[编程交流] DWGs in folder & sub-folders

[复制链接]

23

主题

75

帖子

58

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
143
发表于 2022-7-5 23:25:18 | 显示全部楼层 |阅读模式
  1. (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?
回复

使用道具 举报

35

主题

2471

帖子

2447

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
174
发表于 2022-7-5 23:36:05 | 显示全部楼层
For one level of sub-folders:
  1. (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)))
回复

使用道具 举报

63

主题

6297

帖子

6283

银币

后起之秀

Rank: 20Rank: 20Rank: 20Rank: 20

铜币
358
发表于 2022-7-5 23:42:31 | 显示全部楼层
Try this recursive code
 
  1. (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))
回复

使用道具 举报

23

主题

75

帖子

58

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
143
发表于 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.
回复

使用道具 举报

63

主题

6297

帖子

6283

银币

后起之秀

Rank: 20Rank: 20Rank: 20Rank: 20

铜币
358
发表于 2022-7-5 23:57:30 | 显示全部楼层
How did you call the function ?
回复

使用道具 举报

23

主题

75

帖子

58

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
143
发表于 2022-7-6 00:05:50 | 显示全部楼层
This one gets the error:
  1. (pulldwgs  "O:\\Project 482 - Sterling Centennial Gas Plant")
 
This code works
  1. (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.
回复

使用道具 举报

63

主题

6297

帖子

6283

银币

后起之秀

Rank: 20Rank: 20Rank: 20Rank: 20

铜币
358
发表于 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 .
回复

使用道具 举报

23

主题

75

帖子

58

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
143
发表于 2022-7-6 00:24:29 | 显示全部楼层
Ok, thank you!
回复

使用道具 举报

63

主题

6297

帖子

6283

银币

后起之秀

Rank: 20Rank: 20Rank: 20Rank: 20

铜币
358
发表于 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 .
回复

使用道具 举报

发表回复

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

QQ|关于我们|小黑屋|乐筑天下 繁体中文

GMT+8, 2025-3-11 00:26 , Processed in 0.563506 second(s), 70 queries .

© 2020-2025 乐筑天下

联系客服 关注微信 帮助中心 下载APP 返回顶部 返回列表