3

给定一个正则表达式和一个目录路径,我如何获得路径与正则表达式匹配的文件序列?

即,我想要

(require '[clojure.java.io :as io])

(regex-file-seq #"\.ssh/.*\.pub$" (io/file "/home")) =>
(#<File /home/x/.ssh/iaf_dsa.pub> #<File ....>)

这花了我几分钟把这些碎片拼凑起来,所以我想我会发布它。

4

2 回答 2

6
(defn regex-file-seq
  "Lazily filter a directory based on a regex."
  [re dir]
  (filter #(re-find re (.getPath %)) (file-seq dir)))
于 2012-10-25T07:26:32.460 回答
3

clj-glob可以为您做到这一点:

(glob "*.{jpg,gif}")
于 2012-10-25T08:44:08.373 回答