permaculture playing cards
The moose likes Java in General and the fly likes Delete Directory Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Delete Directory" Watch "Delete Directory" New topic

Delete Directory

bob morkos
Ranch Hand

Joined: Sep 06, 2001
Posts: 104
How do you write a java application that deletes a directory. An example would help a lot. And is it posible to read the size of a file in a java program. Thanks.
Jim Yingst

Joined: Jan 30, 2000
Posts: 18671
The File class has methods delete() and length() which accomplish what you need.

"I'm not back." - Bill Harding, Twister
Spencer J Lee
Ranch Hand

Joined: Mar 19, 2003
Posts: 30
I noticed that the delete method of the File class can only delete a directory if its empty. Is there an existing way or method to recursively delete a directory, its subdirectories, and files (i.e. rm -rf)? Or is this something I'll need to put together myself.
Thanks ahead of time.
Billybob Marshall
Ranch Hand

Joined: Jan 27, 2004
Posts: 202
Originally posted by Spencer Lee:
...Or is this something I'll need to put together myself.

I agree. Here's the link:
subject: Delete Directory
It's not a secret anymore!