Home >Backend Development >PHP Tutorial >php delete entire directory through recursive function
How to delete an entire directory through recursive function in php? This article mainly introduces the recursive function implemented in PHP to delete the entire directory, using PHP recursive algorithm and directory operation skills. I hope to be helpful.
The example in this article describes the PHP implementation of a recursive function for deleting the entire directory. Share it with everyone for your reference. The specific implementation method is as follows:
<?php 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); ?>
Related recommendations:
php Three implementation methods of recursive functions
php Recursive statistics of the number of folders and files
The above is the detailed content of php delete entire directory through recursive function. For more information, please follow other related articles on the PHP Chinese website!