Created
April 15, 2012 22:42
-
-
Save jblomo/2395175 to your computer and use it in GitHub Desktop.
Some filesystem operations in Clojure
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
(defn- cpr! | |
"Recursive copy. src and dst are directories. The *contents* of src will be | |
copied *into* dst (just as if you included trainling slashes in the rsync | |
command)." | |
[src dst] | |
(when (not (.exists dst)) | |
(.mkdir dst)) | |
(let [root-len (count (.getPath src)) | |
relative (fn [file] | |
(.. file getPath (substring (inc root-len))))] | |
(doseq [path (rest (file-seq src))] | |
(let [dst-file (io/file dst (relative path))] | |
(if (.isDirectory path) | |
(.mkdir dst-file) | |
(io/copy path dst-file)))))) | |
(defn- rmr! | |
"Recursively delete a directory or file" | |
[target] | |
(doseq [file (reverse (file-seq target))] | |
(.delete file))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment