• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Deleting an entire directory with File class's delete method

 
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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 ]
    Bookmark Topic Watch Topic
  • New Topic