我们可以使用RecursiveDirectoryIterator 和 RecursiveIteratorIterator删除目录和子目录及文件,子目录将先与父目录删除 ?phpfunction cleanup_directory($dir) { $iter = new RecursiveDirectoryIterator($dir); foreach (ne
我们可以使用RecursiveDirectoryIterator 和 RecursiveIteratorIterator删除目录和子目录及文件,子目录将先与父目录删除
<?php function cleanup_directory($dir) { $iter = new RecursiveDirectoryIterator($dir); foreach (new RecursiveIteratorIterator($iter, RecursiveIteratorIterator::CHILD_FIRST) as $f) { if ($f->isDir()) { rmdir($f->getPathname()); } else { unlink($f->getPathname()); } } rmdir($dir); } cleanup_directory('c:\\wamp\\junk'); ?>