delete-file

clojure.java.io

  • (delete-file f & [silently])
Delete file f. Raise an exception if it fails unless silently is true.

1 Example top

  • ;; 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=>
Log in to add / edit an example.

See Also top

Log in to add a see also.

Plus_12x12 Minus_12x12 Source clojure/java/io.clj:407 top

(defn delete-file
  "Delete file f. Raise an exception if it fails unless silently is true."
  {:added "1.2"}
  [f & [silently]]
  (or (.delete (file f))
      silently
      (throw (java.io.IOException. (str "Couldn't delete " f)))))
Vars in clojure.java.io/delete-file:
Used in 0 other vars

Comments top

No comments for delete-file. Log in to add a comment.