This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Java in General and the fly likes Forced Directory Deletion Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Forced Directory Deletion" Watch "Forced Directory Deletion" New topic
Author

Forced Directory Deletion

Tom Johnson
Ranch Hand

Joined: May 11, 2005
Posts: 142
Hi,
Is there any way to force java to delete a directory, even if its not empty - similar to

rm -f <dir_name> in unix?

Would it be just as handy to create a script with rm -f <dir_name> and call that from the java program?

Thanks

/Tom


<a href="http://faq.javaranch.com/java/UseCodeTags" target="_blank" rel="nofollow">Use Code Tags!!</a>
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18544
    
  40

Originally posted by Tom Johnson:
Hi,
Is there any way to force java to delete a directory, even if its not empty - similar to

rm -f <dir_name> in unix?

Would it be just as handy to create a script with rm -f <dir_name> and call that from the java program?

Thanks

/Tom


The closest equivalent to "rm -f <dir_name>" in Windows is probably "rmdir /s/q <dir_name>".

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Tom Johnson
Ranch Hand

Joined: May 11, 2005
Posts: 142
Hi,
Is that not just a DOS command? - I meant a piece of java code or API to allow me to to it

/tom
Joanne Neal
Rancher

Joined: Aug 05, 2005
Posts: 3432
    
  12
I think you would have to recursively delete the contents of the directory, before deleting the directory itself.


Joanne
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18544
    
  40

Originally posted by Tom Johnson:
Hi,
Is that not just a DOS command? - I meant a piece of java code or API to allow me to to it

/tom


Sorry... I was under the impression that you were calling Runtime.exec() under unix, and needed the equivalent for DOS.

Henry
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Forced Directory Deletion
 
Similar Threads
Problem with deploying a war file on tomcat
Null Pointer Exception
newbie: passing configuration param to WS
creating folder with ant
Calling a Java Program through CRONTAB