• Post Reply Bookmark Topic Watch Topic
  • New Topic

cant delete folder  RSS feed

 
jaki jane
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here's the code:


As you can see, I'm deleting all the files inside and making sure the directory is empty before deleting it. Yet it won't get deleted. I have even tried using FileUtils (commons api) but even that gives the same result.
 
Brian Lang
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What OS are you working with? What permissions are set on that directory?
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Note that Windows won't let you delete a directory if any process has that directory as its current working directory, or if the directory is not empty. It won't let you delete a file that's open for reading or writing. I notice in this code you're not checking the boolean return value of delete(), which returns false for failure.
 
jaki jane
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Im using windows and have full control on the directory. And the boolean value returned is false even when the directory is completely empty. I can delete the folder manually just fine
 
Rob Spoor
Sheriff
Posts: 21133
87
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by jaki jane:

That will create a File object representing a file with the given name in the current directory. You want to give it a parent too:


Or, you could try iDir.listFiles() instead of iDir.list() - the former gives you a File[] instead of a String[].
 
jaki jane
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The weird thing is, when the program is run independently it's able to delete the folder. But not when packaged into a jar
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!