乐筑天下

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

[原创]列出给定路径下所有路径名(包含子目录)或者文件名(包含子目录)

[复制链接]

26

主题

258

帖子

9

银币

后起之秀

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

铜币
361
发表于 2008-3-7 22:42:00 | 显示全部楼层 |阅读模式
;-------------------------------------------------------------------------------
; Program Name: directory.lsp
; Created By:   xshrimp (Email: )
;               (URL: )
; Date Created: 3-7-08
; Function:    列出给定路径下所有路径名(包含子目录)或者文件名(包含子目录)
;-------------------------------------------------------------------------------
;|函数类似vl-directory-files
语法
   (gps->directory-files  directory pattern directories)
功能
   列出给定路径下所有路径名(包含子目录)或者文件名(包含子目录)
说明
  1)参数 directory 为字符串,指定要收集文件的目录。
    若未指定该参数或参数为 nil,那么gps->directory-files 使用当前目录。
  2)参数 pattern 为字符串,包含文件名的 DOS 方式。
    如果未指定该参数或参数为 nil,gps->directory-files 假定为 "*.*"。
  3)directories 为整数型,指定返回的表中是否包含路径名。可以指定下列值之一:
    -1   仅列出目录。
     0   列出文件和目录(缺省值)。
     1   仅列出文件。
返回值:
文件和路径列表。若没有符合指定方式的文件,则返回 nil。
;测试
(gps->directory-files "D:\\xx" nil  1)
(gps->directory-files "D:\\Downloads" "*.exe" 1)
  1. (defun gps->directory-files  (directory pattern directories / allpathlst gps->get-path lst n pathlst x y)
  2. (if (null pattern)     (setq pattern "*.*"))
  3. (if (null directories) (setq directories 0))
  4. ;返回目录下的所有子目录
  5. ;(gps->get-allpath "E:\\Program Files")
  6. ;(gps->get-allpath "f:\\tu")
  7. (defun gps->get-allpath(directory pattern / allpathlst lst n pathlst x gps->get-path)
  8. (if (= (type directory) 'STR)
  9. (progn
  10. (setq directory (vl-string-right-trim  "\\/ " directory))
  11. (setq allpathlst (list directory))
  12. (defun gps->get-path (directory / lst n pathlst x)
  13. (if (and (setq lst (vl-directory-files directory nil -1));仅目录
  14.          (setq lst (vl-remove-if '(lambda (x) (or (= "." x)(= ".." x))) lst))  
  15.      )
  16.       (progn
  17.        (setq pathlst (mapcar '(lambda(x)(strcat directory "" x) )  lst))
  18.        (setq allpathlst (append allpathlst pathlst))
  19.        (foreach n pathlst (gps->get-path n ))            
  20.       )
  21. );end if
  22. )
  23. (gps->get-path directory)
  24. allpathlst
  25. ))
  26. )
  27. ;返回目录下的所有目录及子目录的文件
  28. ;(gps->get-allfile directory pattern)
  29. ;(gps->get-allfile "D:\\Downloads" "*.exe")
  30. (defun gps->get-allfile(directory pattern / x y)
  31. (apply
  32.   'append
  33.   (mapcar
  34.     '(lambda (x)
  35.        (mapcar
  36.   '(lambda (y)
  37.      (strcat x "" y)
  38.    )
  39.   (vl-directory-files x pattern 1);仅仅文件
  40.        )
  41.      )
  42.     (gps->get-allpath directory pattern)
  43.   )
  44. )
  45. )
  46. (cond
  47. ((= -1 directories) (if (= pattern "*.*")(gps->get-allpath directory pattern)));仅列出目录
  48. ((=  0 directories)
  49. (if (/= pattern "*.*")
  50.      (gps->get-allfile directory pattern)
  51.      
  52.       (apply
  53. 'append
  54. (list
  55.    (gps->get-allpath directory pattern)
  56.    (gps->get-allfile directory pattern)
  57. )
  58.       )
  59.       
  60. )
  61. )
  62. ((=  1 directories) (gps->get-allfile directory pattern));仅列出文件
  63. )
  64. )

本帖以下内容被隐藏保护;需要你回复后,才能看到!

游客,如果您要查看本帖隐藏内容请回复
回复

使用道具 举报

30

主题

95

帖子

7

银币

后起之秀

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

铜币
215
发表于 2010-7-9 21:35:00 | 显示全部楼层
谢谢楼主,正需要这个
回复

使用道具 举报

65

主题

268

帖子

9

银币

中流砥柱

Rank: 25

铜币
527
发表于 2010-7-10 00:03:00 | 显示全部楼层
不错不错!!!收藏了
回复

使用道具 举报

15

主题

644

帖子

20

银币

中流砥柱

Rank: 25

铜币
698
发表于 2010-7-10 09:27:00 | 显示全部楼层
感谢楼主分享学习!
回复

使用道具 举报

0

主题

8

帖子

4

银币

初来乍到

Rank: 1

铜币
8
发表于 2011-12-6 17:36:00 | 显示全部楼层
感谢了。楼主。分享了
回复

使用道具 举报

144

主题

646

帖子

6

银币

顶梁支柱

Rank: 50Rank: 50

铜币
1222
发表于 2012-4-9 12:02:00 | 显示全部楼层
谢谢,收藏了,呵呵
回复

使用道具 举报

xgr

56

主题

302

帖子

8

银币

中流砥柱

Rank: 25

铜币
526
发表于 2012-6-14 00:52:00 | 显示全部楼层
这样的必须顶
回复

使用道具 举报

36

主题

319

帖子

15

银币

后起之秀

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

铜币
471
发表于 2012-6-14 05:53:00 | 显示全部楼层
老大的作品都很经典。
回复

使用道具 举报

45

主题

167

帖子

6

银币

后起之秀

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

铜币
347
发表于 2012-6-14 06:34:00 | 显示全部楼层
谢谢,收藏了
回复

使用道具 举报

0

主题

10

帖子

6

银币

初来乍到

Rank: 1

铜币
10
发表于 2022-7-19 08:00:00 | 显示全部楼层
谢谢分享
回复

使用道具 举报

发表回复

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

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

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

GMT+8, 2025-3-4 01:35 , Processed in 0.949438 second(s), 72 queries .

© 2020-2025 乐筑天下

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