Solved

NEWBIE: How to delete all files in a directory? (W2k)

Posted on 2006-11-01
5
257 Views
Last Modified: 2010-03-31
Dear Experts,

Is there a simple way to delete all files in a W2K directory, without actually getting a list of all names and looping?

Thanks,
BrianMc1958
0
Comment
Question by:BrianMc1958
  • 3
  • 2
5 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 17850929
Runtime.getRuntime().exec("cmd.exe /C rmdir /SQ " + dirName);

but be careful with that
0
 

Author Comment

by:BrianMc1958
ID: 17851000
Seems like I've heard that before somewhere...

Although you have answered my question, I'd like to heed your warning and not use it.  I also try to avoid Runtime.
(I'll still split points if anyone else responds...)  

Does anyone know a simple way to do it otherwise?

0
 
LVL 86

Accepted Solution

by:
CEHJ earned 500 total points
ID: 17851029
No - you will have to recurse all files/dirs and delete them first.

http://javaalmanac.com/egs/java.io/TraverseTree.html
0
 

Author Comment

by:BrianMc1958
ID: 17851153
Got it.  Thanks.  That will be very helpful in the future, too.
--BrianMc1958
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 17851190
:-)
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

820 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question