Skip to content

Instantly share code, notes, and snippets.

@tebeka
Created January 20, 2011 21:14
Show Gist options
  • Save tebeka/788685 to your computer and use it in GitHub Desktop.
Save tebeka/788685 to your computer and use it in GitHub Desktop.
Iterate over a directory
(import 'java.io.File)
(require '[clojure.zip :as zip])
(defn branch? [f]
(.isDirectory f))
(defn children [f]
(.listFiles f))
(defn iterzip [z]
"Iterate over a zip, returns a sequence of the nodes"
(when (not (zip/end? z))
(cons (zip/node z) (lazy-seq (iterzip (zip/next z))))))
(defn iterdir [path]
(iterzip (zip/zipper branch? children nil (File. path))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment