Results 1 to 2 of 2
- 03-26-2010, 09:40 AM #1
Member
- Join Date
- Feb 2010
- Posts
- 11
- Rep Power
- 0
wait until directory is completely deleted
Hi,
I have a directory that contains a lot of files. I want to delete the entire directory as well as all the files in it.
I want my code to wait until every File in that directory (including the directory itself) is deleted before the next command is executed.
Here is what I have so far:
deleteDir(new File(path_to_dir)); //custom made method deletes dir and files in it
while((new File(path_to_dir)).exists()) {
//wait
}
//continue executing other commands
Do you think that this while loop will make sure that all files and the dir are deleted before the next command is executed?
Other (more elegant/secure) solutions to this?
thanks in advance,
nick
- 03-26-2010, 01:08 PM #2
in the given example,
the while loop is useless, because you are invoking a method which will not return unless the task inside of that method is done or if that method is executing a thread that will remove all files on a specific folder.
The risk if you force to do it that way is most of the CPU consumption will be from your program.
Other applications will slowdown their performance(slightly on quadcore processors). I don't know if you are aware of it.
a suggestion:
Instead, let thread1 execute the delete method and put some sleep to it. and execute another thread2 that checks the directory every 5 to 10 milliseconds, when the directory is empty, do the desired commands also in thread2.Last edited by sukatoa; 03-26-2010 at 01:10 PM.
freedom exists in the world of ideas
Similar Threads
-
How to Recover Deleted Files from Eclipse ?
By vinod827 in forum EclipseReplies: 1Last Post: 08-02-2009, 12:07 PM -
Is JAVA completely object-oriented???
By venkateshk in forum New To JavaReplies: 2Last Post: 11-17-2008, 09:17 AM -
Completely new to Java problem
By Seamo14 in forum New To JavaReplies: 4Last Post: 10-09-2008, 12:50 PM -
Files not completely deleted on Linux
By amamare in forum Advanced JavaReplies: 0Last Post: 12-19-2007, 02:12 PM -
I am completely stuck
By jpnym15 in forum New To JavaReplies: 2Last Post: 11-14-2007, 06:40 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks