Skip to content

Instantly share code, notes, and snippets.

@rauhs
Last active August 29, 2015 14:27
Show Gist options
  • Save rauhs/63054a06631c0be598d3 to your computer and use it in GitHub Desktop.
Save rauhs/63054a06631c0be598d3 to your computer and use it in GitHub Desktop.
Clojure: List files in directory
(ns x.y
(:import
[java.io File]))
(defn ls-match
"Given the directory handle d, lists all files matching the given
regex. Returns the Java File instances.
Example:
(ls-match (File. \"./dir\") #\"(?i).drl$\")"
([^File d]
(ls-match d #"^[~_.]"))
([^File d regex]
(.listFiles d
(reify
java.io.FileFilter
(accept [this f]
(and
(.isFile f)
(boolean (re-find regex (.getName f)))))))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment