Last active
December 28, 2015 09:19
-
-
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.
This file contains 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
; | |
; 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