本文實例講述了php中通過DirectoryIterator刪除整個目錄的方法。分享給大家供大家參考。具體實現方法如下:
<?php
function cleanup_directory($dir) {
foreach (new DirectoryIterator($dir) as $file) {
if ($file->isDir()) {
if (! $file->isDot()) {
cleanup_directory($file->getPathname());
}
} else {
unlink($file->getPathname());
}
}
rmdir($dir);
}
?>
希望本文所述對大家的php程序設計有所幫助。