• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Deleting an entire directory with File class's delete method

 
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When I use the File class's .delete() method to delete an empty directory, it works. However, if the directory contains files or subdirectories, it is not deleted. Is it possible for me to delete a directory, and all it's files and sub-directories in one fell swoop, without having to delete the contents first???
Any advice will be greatly appreciated.
[ July 21, 2004: Message edited by: Bill Brasskey ]
 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No, you will have to delete all of the contents first.
 
Ranch Hand
Posts: 531
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Only by hand, unfortunately. I recall Java having a mechanism where you have to laboriously find out and then delete all files. Fortunately, it is rather easy.

What you could do, though, is to extend File (I don't remember if it's final or not, sorry) and reimplement the delete method to search and delete all files by default. Thus you will just call delete, and it will be all nicely accomplished without undue effort.
[ July 22, 2004: Message edited by: Anton Golovin ]
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic