Created
August 5, 2010 05:59
-
-
Save zk/509311 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
(defmacro with-temp-dir [dir & body] | |
`(when-let [temp-file# (java.io.File/createTempFile (.toString (java.util.UUID/randomUUID)) "")] | |
(.delete temp-file#) | |
(.mkdirs temp-file#) | |
(when-let [temp-dir# (.getAbsolutePath temp-file#)] | |
((fn [~dir] | |
(let [res# (do ~@body)] | |
(clojure.contrib.io/delete-file-recursively temp-dir#) | |
res#)) temp-dir#)))) | |
;; Usage | |
(with-temp-dir tmp | |
(println (str "Temp Directory: " tmp ", will be deleted when this function returns..."))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment