Created
April 17, 2014 12:31
-
-
Save kurogelee/10979727 to your computer and use it in GitHub Desktop.
Clojureでglobでのファイル検索 ref: http://qiita.com/kurogelee/items/97bccacf69e95a338e6d
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(files-glob "." "**/*.clj") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(require '[clojure.java.io :as io]) | |
(require '[clojure.string :as s]) | |
(import '[java.nio.file FileSystem FileSystems]) | |
(import '[java.io File]) | |
(def file-separator (System/getProperty "file.separator")) | |
(defn files-glob [dir glob] | |
(let [dir (io/as-file dir) | |
path (str "glob:" (.getPath (io/file dir glob))) | |
path (if (= file-separator "\\") (s/replace path "\\" "\\\\") path) | |
m (.. ^FileSystem (FileSystems/getDefault) (getPathMatcher path))] | |
(filter #(.matches m (.toPath ^File %)) (file-seq dir)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment