-
-
Save film42/39738441956f579b0743 to your computer and use it in GitHub Desktop.
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
(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