Created
November 18, 2011 05:22
-
-
Save xiaonaitong/1375667 to your computer and use it in GitHub Desktop.
print directory structure
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
(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