1. 程式人生 > >刪除文件或目錄

刪除文件或目錄

tca sub $path exist urn return sta item HA

function delDirAndFile($path, $delDir = FALSE)
{
if (is_array($path)) {
foreach ($path as $subPath)
delDirAndFile($subPath, $delDir);
}
if (is_dir($path)) {
$handle = opendir($path);
if ($handle) {
while (false !== ($item = readdir($handle))) {
if ($item != "." && $item != "..")

is_dir("$path/$item") ? delDirAndFile("$path/$item", $delDir) : unlink("$path/$item");
}
closedir($handle);
if ($delDir)
return rmdir($path);
}
} else {
if (file_exists($path)) {
return unlink($path);
} else {

return FALSE;
}
}
clearstatcache();
}

刪除文件或目錄