I am trying to build a directory tree such as how xml trees are represented, in the form of a vector, i can traverse the file system fine using the following snippet but i can’t put my head around how to build a tree structure out of this?
(defn trav [dir]
(if (.isDirectory dir)
(do
(println (.getName dir))
(doseq [file (.listFiles dir)]
(if (.isDirectory file)
(trav file)))
)))
How about this?
If you query the resulting map for
:fileyou get the file entry for this node back. If you ask for:contentsand getnil, it’s a file. A vector indicates a directory.As Carl already said: maybe
file-seqis more appropriate.