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

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

Question by:BrianMc1958
  • 3
  • 2
LVL 86

Expert Comment

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

but be careful with that

Author Comment

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?

LVL 86

Accepted Solution

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

Author Comment

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

Expert Comment

ID: 17851190

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

For customizing the look of your lightweight component and making it look opaque like it was made of plastic.  This tip assumes your component to be of rectangular shape and completely opaque.   (CODE)
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 scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…

746 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

12 Experts available now in Live!

Get 1:1 Help Now