我想找到以.jpg、.png或.jpeg结尾的所有文件。我写了这样的东西:
(defun get-picture (dir)
(remove-if-not (lambda (item)
(or (string= ".jpg" (pathname-type item))
(string= ".png" (pathname-type item))
(string= ".jpeg" (pathname-type item))))
(uiop:directory-files dir)))但在我看来不太好。例如,当您想要搜索更多。所以我写了这个:
(defun search-file (dir file-types)
(remove-if-not (lambda (item)
(mapc (lambda (type)
(string= type (pathname-type item)))
file-types))
(uiop:directory-files dir)))但是很明显,mapc在这里是不正确的。所以我想知道是否有更好的做法(除了玩偶)?
发布于 2021-03-14 10:10:23
(defun get-picture-files (d &key
(extensions '("jpg" "png" "jpeg"))
(test #'string-equal))
(remove-if (lambda (p)
(not (member (pathname-type p)
extensions
:test test)))
(uiop:directory-files d)))这
extensions;
pathname-type只使用一次;
remove-if-not。)
https://stackoverflow.com/questions/66623074
复制相似问题