Today, We are going to learn PHP remove non-empty directory. PHP provides rmdir function using that we can easily remove any directory. But When you are going to remove a non-empty directory using rmdir it’s fire exception. You can’t able to remove non-empty directory message something like The directory is not empty.

PHP remove non-empty directory

So Let’s see, how we can remove a non-empty directory. I am going to share function with you using that function you can able to remove a non-empty directory.

First of all, Place this function with your code. Now, you just need to pass the directory path as a parameter to deleteDirectory function like.

finally, Now you can able to remove a non-empty directory. You can get more detail about this function from here.

If you face any issue after using this function write the comment below.

Leave a Reply