This week's book giveaway is in the Agile and other Processes forum.
We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line!
See this thread for details.
The moose likes Java in General and the fly likes Directory deleting Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "Directory deleting" Watch "Directory deleting" New topic
Author

Directory deleting

Barry Brashear
Ranch Hand

Joined: Jun 05, 2001
Posts: 303
Is there a way to delete a top level directory and all sub directories?
I think the File.delete() method only deletes empty directories.

Thanks.
Jesper de Jong
Java Cowboy
Bartender

Joined: Aug 16, 2005
Posts: 12924
    
    3

You mean, delete a directory with all the files and subdirectories in it with one command?

No, there is no such command in Java. You'll have to traverse directory depth first (recursively) and delete all files and directories you encounter.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
Or you use the FileUtils class from http://jakarta.apache.org/commons/io/


The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Adam Richards
Ranch Hand

Joined: Nov 03, 2005
Posts: 133
See here for how to traverse a directory tree.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Directory deleting
 
Similar Threads
Files
Debugging JSP
container starts up and deployed web application.
Package
Layout assistance please