Skip to content

Instantly share code, notes, and snippets.

@jblomo
Created April 15, 2012 22:42
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 jblomo/2395175 to your computer and use it in GitHub Desktop.
Save jblomo/2395175 to your computer and use it in GitHub Desktop.
Some filesystem operations in Clojure
(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