Last active
August 29, 2015 14:27
-
-
Save rauhs/63054a06631c0be598d3 to your computer and use it in GitHub Desktop.
Clojure: List files in directory
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
(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