This article mainly introduces the php implementation of the recursive function for deleting the entire directory, involving php recursive algorithm and directory operation skills , friends in need can refer to it
The example in this article describes the PHP implementation of a recursive function for deleting an entire directory. Share it with everyone for your reference. The specific implementation method is as follows:
?
3 4 513 14
15
16
17
|
<🎜>function delete_directory($dir) {<🎜> <🎜>if ($dh = @opendir($dir)) {<🎜> <🎜>while (($file = readdir ($dh)) != false) {<🎜> <🎜>if (($file == ".") || ($file == "..")) continue;<🎜> <🎜>if (is_dir($dir . '/' . $file))<🎜> <🎜>delete_directory($dir . '/' . $file);<🎜> <🎜>else<🎜> <🎜>unlink($dir . '/' . $file);<🎜> <🎜>}<🎜> <🎜>@closedir($dh);<🎜> <🎜>rmdir($dir);<🎜> <🎜>}<🎜> <🎜>}<🎜> <🎜>$dir = "./fakeDir";<🎜> <🎜>delete_directory($dir);<🎜> <🎜>?> |