aspose file tools*
The moose likes Java in General and the fly likes How Do I completely Empty My DIrectory? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "How Do I completely Empty My DIrectory?" Watch "How Do I completely Empty My DIrectory?" New topic
Author

How Do I completely Empty My DIrectory?

Stanley Mungai
Ranch Hand

Joined: Dec 09, 2011
Posts: 155

Hi guys,

Will Someone please tell me Why this code of mine is deleting some files and leavind some behind while I want the Directory to be completely Emptied!!!

My Code is


Well it is just that I thought it should clear the directory.


Give a beggar a fish; feed him for a day. Teach him how to fish; Feed him for a lifetime.
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 13868
    
  10

There are different reasons why files cannot be deleted; for example (on Windows) when some process has the file open, or when the user doesn't have permission to delete the file. If these are files that you read or wrote in your own Java program, make sure that you close the file (or any input / output streams on the file) before you try to delete it.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
Mohamed Sanaulla
Saloon Keeper

Joined: Sep 08, 2007
Posts: 3054
    
  33

And Your directory might contain other directories in which case you would have to go into those and delete the files there in as well, if at all empty according to you is no files/directories to be present.


Mohamed Sanaulla | My Blog
Stanley Mungai
Ranch Hand

Joined: Dec 09, 2011
Posts: 155

Thank you Mohamed and Jesper,

I have Closed all the inputstreams but there is no positive change.

The situation is am Having text files which are getting converted to Pdf. The pdfs are getting sent to an e-mail adress contained in the text files. The program is then supposed to delete both the pdfs and the text files. All the pdfs are getting deleted and Some of the text files. The question is now that the program is reading from all the text files and sending all the Pdfs, Why isn't it deleting all the text files but choosing which ones to delete and leaving some? I do not have other Directories in the same Directory.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How Do I completely Empty My DIrectory?
 
Similar Threads
Java directory
How do I make a list of folders only record the file name and not the directory it's in?
exe file to get the property of the files in a folder
How to get all files in a subdirectory of a webpage
Opening a file