Solved

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

Posted on 2006-11-01
5
240 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Core Java. What output will be and why ? 6 66
create a gui in perl 3 72
Free Alternative to JIRA 4 91
java.io.BufferedReader   readLine()  //returns the entire file ? 4 60
An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

895 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now