5

Is there a way to bypass a java.nio.file.DirectoryNotEmptyException? I want to be able to delete a folder with content in it.

Saket
  • 3,079
  • 3
  • 29
  • 48
Lucas Baizer
  • 305
  • 2
  • 5
  • 13
  • I think you need to delete the contents, then delete the directory. – Mike Ounsworth Apr 26 '15 at 01:20
  • 1
    Not a duplicate. This question is asking if you can delete a directory *without* doing all of that. – Stephen C Apr 26 '15 at 01:37
  • @StephenC: [After looking at the documentation](http://docs.oracle.com/javase/7/docs/api/java/nio/file/Files.html#delete(java.nio.file.Path)) and the suggested duplicate, I'm more inclined to think it *is* a dupe. – Makoto Apr 26 '15 at 04:29

2 Answers2

1

No, you cannot bypass it. You have to delete the files and sub-directories first in the folder. There are many examples available on the web for how to do this.

dave
  • 11,641
  • 5
  • 47
  • 65
1

Is there a way to bypass a java.nio.file.DirectoryNotEmptyException?

No. There is no way to bypass it.

On Linux / Unix, the restriction is ultimately imposed by the operating system. See man 2 rmdir, and the ENOTEMPTY error code.

Also, try running rmdir from the command prompt on a non-empty directory, and see what happens.


As other comments state, you need to empty the directory first.

Stephen C
  • 698,415
  • 94
  • 811
  • 1,216