R – Building the directory tree


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)
      (println (.getName dir))
      (doseq [file (.listFiles dir)]
        (if (.isDirectory file)
          (trav file)))      

Best Solution

I'm not really good at this either, but...

were you aware that there is already a "built in" function to turn a directory tree into a sequence?

See http://richhickey.github.com/clojure/clojure.core-api.html#clojure.core/file-seq .

Maybe this will meet your needs. Otherwise, we'll just wait until the really smart Clojurians show up.

Related Question