Skip to content

Instantly share code, notes, and snippets.

@kurogelee
Created April 17, 2014 12:31
Show Gist options
  • Save kurogelee/10979727 to your computer and use it in GitHub Desktop.
Save kurogelee/10979727 to your computer and use it in GitHub Desktop.
Clojureでglobでのファイル検索 ref: http://qiita.com/kurogelee/items/97bccacf69e95a338e6d
(files-glob "." "**/*.clj")
(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