function unlinkrecursiv($path) { if (mb_substr($path, -1) != '/') { $path .= '/'; } $notunlinked = 0; $hDir = opendir($path); while (false !== ($file = readdir($hDir))) { if ($file != '.' && $file != '..') { if (is_dir($path . $file)) { if (unlinkrecursiv($path . $file . '/') == false) { $notunlinked++; } } else { if (mb_substr($file, -4) == '.zip' || mb_substr($file, -3) == '.gz' || mb_substr($file, -4) == '.bz2' || mb_substr($file, -4) == '.xml') { unlink($path . $file); } else { $notunlinked++; } } } } closedir($hDir); if ($notunlinked == 0) { rmdir($path); return true; } else { return false; } }
function unlinkrecursiv($path) { // This loop can be started simultaneously by multiple synchronous XML // requests, which both try to delete entries, files and directories. // Therefore errors must be gracefully ignored. if (mb_substr($path, -1) != '/') { $path .= '/'; } $notunlinked = 0; $hDir = opendir($path); if ($hDir === false) { ++$notunlinked; } else { while (false !== ($file = readdir($hDir))) { if ($file != '.' && $file != '..') { if (is_dir($path . $file)) { if (unlinkrecursiv($path . $file . '/') == false) { $notunlinked++; } } else { if (mb_substr($file, -4) == '.zip' || mb_substr($file, -3) == '.gz' || mb_substr($file, -4) == '.bz2' || mb_substr($file, -4) == '.xml') { @unlink($path . $file); } else { $notunlinked++; } } } } closedir($hDir); } if ($notunlinked == 0) { @rmdir($path); return true; } else { return false; } }