Skip to content

Instantly share code, notes, and snippets.

@xiaonaitong
Created November 18, 2011 05:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xiaonaitong/1375667 to your computer and use it in GitHub Desktop.
Save xiaonaitong/1375667 to your computer and use it in GitHub Desktop.
print directory structure
(use 'clojure.java.io)
(defn depth [x]
(count (filter #(= % java.io.File/separatorChar) (.getAbsolutePath x))))
(defn pfile [x]
(let [root-depth (depth x)]
(fn [y]
(let [rdepth (- (depth y) root-depth)
prefix (apply str (repeat (* 3 rdepth) \space))
sign (if (.isDirectory y) "+" "-")
fname (.getName y)]
(println prefix sign fname)))))
(defn print-dir [x]
(let [root (file x)]
(dorun
(map (pfile root) (file-seq root)))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment