Recurses thru a directory looking for 'test.txt' files and cats the result to the output file and stdout.
(import
'(java.io File FileWriter BufferedReader FileReader))
(def myfile (new File "C:\temp\source\"))
(def myfile2 (new File "C:\temp\out.txt"))
(defn recurse-files [file]
(if (.isDirectory file)
(apply str (map recurse-files (.listFiles file)))
(when (= (.getName file) "test.txt")
(let [reader (new BufferedReader (new FileReader file))]
(apply str (map
#(str (.getParent file) "/" % \newline)
(line-seq reader)))))))
(doto (new FileWriter myfile2)
(.write (recurse-files myfile))
(.close))
(recurse-files myfile)
No comments:
Post a Comment