Skip to content

Instantly share code, notes, and snippets.

@frankhale
Last active December 28, 2015 09:19
Show Gist options
  • Save frankhale/7477765 to your computer and use it in GitHub Desktop.
Save frankhale/7477765 to your computer and use it in GitHub Desktop.
(learning Clojure) So I need a function that walks a set of directories and recursively gets the files paths contained in them. Here is my attempt.
;
; Still learning Clojure...
;
; Walk a directory or a series of directories and return a map of their files paths
;
; I initially started with the directory walk example here:
;
; http://rosettacode.org/wiki/Walk_a_directory/Recursively#Clojure
;
(defn walk [dirpaths pattern]
(let [get-files (fn [dirpath]
(doall
(filter #(re-matches pattern %)
(map #(.getAbsolutePath %)
(filter #(.isFile %) (file-seq (file dirpath)))))))]
(apply concat (map #(get-files %) dirpaths))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment