Skip to content

Instantly share code, notes, and snippets.

@FelipeCortez
Created February 19, 2020 01:25
Show Gist options
  • Save FelipeCortez/4e57a8f1929c7b6c0d1f300d2922f580 to your computer and use it in GitHub Desktop.
Save FelipeCortez/4e57a8f1929c7b6c0d1f300d2922f580 to your computer and use it in GitHub Desktop.
(require '[clojure.java.io :as io])
(defn visit-print
"println approach"
[path level]
(when (some #(clojure.string/includes? % ".md") (file-seq (io/file path)))
(println (str (apply str (repeat level " ")) "- " (.getName (io/file path))))
(doseq [path (.listFiles (io/file path))] (visit-print path (inc level)))))
(defn visit-print
"immutable approach"
[path level]
(when (some #(clojure.string/includes? % ".md") (file-seq (io/file path)))
(filter seq [(str (apply str (repeat level " ")) "- " (.getName (io/file path)))
(filter seq
(map #(visit-print % (inc level))
(.listFiles (io/file path))))])))
(->> (visit-print "/home/felipecortez/Dev/playbooks" 0)
flatten
(clojure.string/join "\n")
(spit "yay.yml"))
(file-seq (io/file "/home/felipecortez/Dev/playbooks"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment