I wonder, what's the easiest way to delete a directory with all its files in it?
I'm using rmdir(PATH . '/' . $value);
to delete a folder, however, if there are files inside of it, I simply can't delete it.
I wonder, what's the easiest way to delete a directory with all its files in it?
I'm using rmdir(PATH . '/' . $value);
to delete a folder, however, if there are files inside of it, I simply can't delete it.
2 cents to add to THIS answer above, which is great BTW
After your glob (or similar) function has scanned/read the directory, add a conditional to check the response is not empty, or an
invalid argument supplied for foreach()
warning will be thrown. So...My full function (as an object method):
This one works for me:
The Best Solution for me
code:
p.s. REMEMBER!
dont pass EMPTY VALUES to any Directory deleting functions!!! (backup them always, otherwise one day you might get DISASTER!!)
Here is the solution that works perfect:
Simple and Easy...
Glob function doesn't return the hidden files, therefore scandir can be more useful, when trying to delete recursively a tree.