Skip to content

Instantly share code, notes, and snippets.

@film42
Created September 24, 2013 08:02
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 film42/39738441956f579b0743 to your computer and use it in GitHub Desktop.
Save film42/39738441956f579b0743 to your computer and use it in GitHub Desktop.
(ns list-em.core
(:require [clojure.string :only (join split)]
[clojure.java.io])
(:gen-class))
(def master-list (atom []))
(defn list-dir [dir-name]
(let [file (new java.io.File dir-name)]
(if (not (.isDirectory file))
;; Is a file, let's save it
(let [file-path (.getAbsolutePath file)]
(swap! master-list conj [file-path])
(str file-path))
;; Is a directory, let's recurse
(let [file-list (.listFiles file)]
;; Send each child through list-dir and return
(map (fn [f] (list-dir (.getAbsolutePath f)))
file-list)))))
(defn save-dir-list [file-name]
(map (fn [s]
(println s)
(spit file-name (str s "\n") :append true)) @master-list))
(defn -main [& args]
(list-dir "/tmp")
(count @master-list)) ;; Returns 0
;; For instant repl
(list-dir "/tmp")
(count @master-list) ;; Returns 92
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment