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