LISP非递归深度遍历文件夹查找文件
本帖最后由 dcl1214 于 2024-8-28 22:41 编辑见过一些递归的查找文件,我来一个非递归的,我想不到递归怎么写,代码如下:
(defun $lie-chu-mu-lu-xia-suo-you-wen-jian$
(lst / a f fs fs-all kzm n ns ns-1 wj wjs)
;列出目录下所有文件,含子级目录,所有目录下的文件
;($lie-chu-mu-lu-xia-suo-you-wen-jian$(list(cons "目录" "C:\\uploads")(cons "扩展名" "*.dwg")))
(or (and lst
(= (type lst) 'list)
(setq kzm (cdr (assoc "扩展名" lst)))
(> (strlen kzm) 0)
(wcmatch kzm "[,`*.*,]")
)
(setq kzm "*.*")
)
(or (and lst
(= (type lst) 'list)
(setq f (cdr (assoc "目录" lst)))
)
(and lst (= (type lst) 'str) (setq f lst))
)
(and
f
kzm
(findfile f)
(progn
(while (and f (wcmatch f "*`\\*"))
(setq f (vl-string-subst "/" "\\" f))
)
(setq fs-all nil)
(setq fs-all (cons f fs-all))
(setq fs (vl-directory-files f "*.*" -1))
(setq fs (vl-remove ".." fs))
(setq fs (vl-remove "." fs))
(setq fs (mapcar (function (lambda (a) (strcat f "/" a))) fs))
(setq fs-all (APPEND fs-all fs))
(while (AND fs (setq f (last fs)) (< (length fs-all) 10000))
(setq ns nil)
(setq ns (vl-directory-files f "*.*" -1))
(setq ns (vl-remove ".." ns))
(setq ns (vl-remove "." ns))
(while (setq a (car ns))
(setq n (strcat f "/" a))
(setq fs (cons n fs))
(setq fs-all (cons n fs-all))
(setq ns (cdr ns))
)
(setq fs (reverse (cdr (reverse fs))))
)
(and fs-all
(progn
(setq wjs nil)
(while (setq a (car fs-all))
(setq wj nil)
(setq wj (vl-directory-files a kzm 1))
(setq wj (vl-remove ".." wj))
(setq wj (vl-remove "." wj))
(setq
wj (mapcar (function (lambda (b) (strcat a "/" b))) wj)
)
(setq wjs (cons wj wjs))
(setq fs-all (cdr fs-all))
)
(setq wjs (vl-remove nil wjs))
)
)
)
)
wjs
)
不错,不错。学习到了。要是可以选择包含“某些字符”就更好了。 thanks for sharing ... learning 感谢杜总的分享! 谢分享,受益非㳀
页:
[1]