aboutsummaryrefslogtreecommitdiff
path: root/src/clojure/contrib/java_utils.clj
diff options
context:
space:
mode:
authorPhil Hagelberg <technomancy@gmail.com>2009-10-08 21:29:25 -0700
committerChouser <chouser@n01se.net>2009-10-28 21:50:46 -0400
commit8eef617aac7b077421d4aa9c84a2df189af6ee17 (patch)
tree469cf322f331efe7faf45f8535361845fe455148 /src/clojure/contrib/java_utils.clj
parentb9c7820e64d4e5b86c837b25800cf61094ad2517 (diff)
java-utils: Add delete-file and delete-file-recursively functions
Also added test for delete-file. Refs #33 Signed-off-by: Chouser <chouser@n01se.net>
Diffstat (limited to 'src/clojure/contrib/java_utils.clj')
-rw-r--r--src/clojure/contrib/java_utils.clj17
1 files changed, 17 insertions, 0 deletions
diff --git a/src/clojure/contrib/java_utils.clj b/src/clojure/contrib/java_utils.clj
index 579d1128..7af4bc93 100644
--- a/src/clojure/contrib/java_utils.clj
+++ b/src/clojure/contrib/java_utils.clj
@@ -175,6 +175,23 @@
(doto (as-properties m)
(.store f #^String comments)))))
+(defn delete-file
+ "Delete file f. Raise an exception if it fails unless silently is true."
+ [f & [silently]]
+ (or (.delete (file f))
+ silently
+ (throw (java.io.IOException. (str "Couldn't delete " f)))))
+
+(defn delete-file-recursively
+ "Delete file f. If it's a directory, recursively delete all its contents.
+Raise an exception if any deletion fails unless silently is true."
+ [f & [silently]]
+ (let [f (file f)]
+ (if (.isDirectory f)
+ (doseq [child (.listFiles f)]
+ (delete-file-recursively child silently)))
+ (delete-file f silently)))
+
(defmulti
#^{:doc "Coerces argument (URL, URI, or String) to a java.net.URL."
:arglists '([arg])}