recursive delete directory (folder) Here are two examples, one is to delete a separate empty directory code, a batch delete directory folder code.
// delete a single empty folder
$ dir = 'www.111cn.net'; if (is_dir ($ dir)) / / to determine whether the directory { if (rmdir ($ dir)) { Echo 'directory deleted successfully'; } else { echo 'did not delete the directory permissions'; } } else { echo 'is not a valid directory'; } Let's look at a batch recursive delete function of the directory.
function deletedir ($ dir) { if (! handle = @ opendir ($ dir)) {// Check if the directory to open exists die ("no such directory"); } while (false! == ($ file = readdir ($ handle))) { if ($ file! == "." && $ file! == "..") {// exclude the current directory from the parent directory $ file = $ dir .directory_separator. $ file; if (is_dir ($ file)) { deletedir ($ file); } else { if (@unlink ($ file)) { echo "file <b> $ file </ b> deleted successfully." } else { echo "file <b> $ file </ b> failed to delete! <br>"; } } } if (@rmdir ($ dir)) { echo "directory <b> $ dir </ b> deleted successfully. <br> n"; } else { echo "directory <b> $ dir </ b> failed to delete! <br> n"; } }
//test program $ dir = "/ var / www / test"; deletedir ($ dir);
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.