Skip to content

Instantly share code, notes, and snippets.

@danielef
Last active March 3, 2017 19:15
Show Gist options
  • Save danielef/5d2218b2296679c32dbe39351e5ca538 to your computer and use it in GitHub Desktop.
Save danielef/5d2218b2296679c32dbe39351e5ca538 to your computer and use it in GitHub Desktop.
Clojure Walk `path` recursivelly (with recur) and retrieves a vector with all regular files
(defn files-in-depth
"Walk `path` recursivelly and retrieves a vector with all regular files"
[path]
(loop [files [] acums [path]]
(if-not (empty? acums)
(if (Files/isDirectory (peek acums) (into-array (LinkOption/values)))
(let [stream (Files/newDirectoryStream (peek acums))]
(recur files (into (pop acums) (iterator-seq (.iterator stream)))))
(recur (conj files (peek acums)) (pop acums)))
files)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment