给定一个正则表达式和一个目录路径,我如何获得路径与正则表达式匹配的文件序列?
即,我想要
(require '[clojure.java.io :as io])
(regex-file-seq #"\.ssh/.*\.pub$" (io/file "/home")) =>
(#<File /home/x/.ssh/iaf_dsa.pub> #<File ....>)
这花了我几分钟把这些碎片拼凑起来,所以我想我会发布它。
(defn regex-file-seq
"Lazily filter a directory based on a regex."
[re dir]
(filter #(re-find re (.getPath %)) (file-seq dir)))
clj-glob可以为您做到这一点:
(glob "*.{jpg,gif}")