This week's book giveaway is in the General Computing forum.
We're giving away four copies of Arduino in Action and have Martin Evans, Joshua Noble, and Jordan Hochenbaum 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
Register / Login


JavaRanch » Java Forums » Java » Java in General
Reply 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: 16815
    
  19

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: 3011
    
    9
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: 16815
    
  19

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://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: Forced Directory Deletion
 
Similar Threads
Calling a Java Program through CRONTAB
newbie: passing configuration param to WS
creating folder with ant
Problem with deploying a war file on tomcat
Null Pointer Exception