function getDir($dir)
{
if (!is_dir($dir)) {
return '$dir不是一个目录';
}
if (!file_exists($dir)) {
return '$dir 文件不存在';
}
$hander = opendir($dir);
if (!$hander) {
return '打开目录句柄失败';
}
while ($hander_path = readdir($hander) !== false) {
if ($hander_path != '.' && $hander_path != '..') {
$filePath = $dir . '/' . $hander_path;
if (is_dir($filePath)) {
getDir($filePath);
}
if (is_file($filePath)) {
unlink($filePath);
}
}
}
closedir($hander);
if (rmdir($dir)) {
return '删除成功';
} else {
return '删除失败';
}
}
$dir = __DIR__ . '/file';
print getDir($dir);