delete-file

added
1.2

ns
clojure.java.io

type
function

(delete-file f & [silently])

Delete file f. Raise an exception if it fails unless silently is true.

                ;; create a file using spit, then show its contents using slurp
;; delete it and verify that it has been deleted by trying to print its
;; contents again

user=> (require '[clojure.java.io :as io])
nil
user=> (spit "stuff.txt" "blurp")
nil
user=> (println (slurp "stuff.txt"))
blurp
nil
user=> (io/delete-file "stuff.txt")
true
user=> (println (slurp "stuff.txt"))
java.io.FileNotFoundException: stuff.txt (The system cannot find the file specif
ied) (NO_SOURCE_FILE:0)
user=>
            
                (require '[clojure.java.io :as io])

user> (io/delete-file "d:/code/python/file-which-does-not-exist.py")
IOException Couldn't delete d:/code/python/exist.py  
clojure.java.io/delete-file (io.clj:426)

user> (io/delete-file "d:/code/python/file-which-does-not-exist.py" true)
true