delete-file implementation (?!)

117 views
Skip to first unread message

AtKaaZ

unread,
Feb 9, 2013, 9:32:02 PM2/9/13
to clo...@googlegroups.com
Hi, does anyone see anything wrong with this?

=> (source clojure.java.io/delete-file)
(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)))))
nil

If you don't already, see below:

=> (.delete (q/newClass java.io.File "a.tx1"))
false
=> (.delete (q/newClass java.io.File "c:\\a.tx1"))
true

=> (clojure.java.io/delete-file (new java.io.File "c:\\a.tx1"))
IOException Couldn't delete c:\a.tx1  clojure.java.io/delete-file (io.clj:425)
=> (clojure.java.io/delete-file (new java.io.File "c:\\a.tx1") true)
true
=> (clojure.java.io/delete-file (new java.io.File "c:\\a.tx1") 1)
1

Yep, I do need it to return the true/false status from .delete
fix?

=> *clojure-version*
{:major 1, :minor 5, :incremental 0, :qualifier "RC14"}




--
Please correct me if I'm wrong or incomplete,
even if you think I'll subconsciously hate it.

Sean Corfield

unread,
Feb 10, 2013, 8:13:38 PM2/10/13
to clo...@googlegroups.com
You can call (clojure.java.io/delete-file some-file :not-deleted) and
you'll get true if the delete succeeds and :not-deleted if it fails.
> --
> --
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clo...@googlegroups.com
> Note that posts from new members are moderated - please be patient with your
> first post.
> To unsubscribe from this group, send email to
> clojure+u...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en
> ---
> You received this message because you are subscribed to the Google Groups
> "Clojure" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to clojure+u...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>



--
Sean A Corfield -- (904) 302-SEAN
An Architect's View -- http://corfield.org/
World Singles, LLC. -- http://worldsingles.com/

"Perfection is the enemy of the good."
-- Gustave Flaubert, French realist novelist (1821-1880)

AtKaaZ

unread,
Feb 10, 2013, 8:26:10 PM2/10/13
to clo...@googlegroups.com
oh great, that's what I was missing and it makes sense now and that strikes me like it's idiomatic clojure coding to do that and that it's also unwritten/expected-of-us-to-know-this

=> (clojure.java.io/delete-file "c:\\1.123" :not-deleted)
true
=> (clojure.java.io/delete-file "c:\\1.123" :not-deleted)
:not-deleted

Thank you for this

Sean Corfield

unread,
Feb 10, 2013, 10:07:48 PM2/10/13
to clo...@googlegroups.com
I added a note on the ticket you created that perhaps the docstring
could be expanded to make this usage clearer.
Reply all
Reply to author
Forward
0 new messages