0

如何删除包含所有文件和目录(递归)的目录,但是当有一个特殊的文件名时,该树及其子级将继续存在?

protected function _removeDir ($dir, &$found)
{
// is this directory exist?
if (!is_dir ($dir))
{
    return false;
}

// is there .ignore?
if (is_file ($dir.'/.ignore'))
{
    $found = true;
    return false;
}

// now iterate
foreach (new DirectoryIterator($dir) as $fileinfo)
{
    $absPath = $dir.'/'.$fileinfo->getFilename();
    if (is_file($absPath))
    {
        unlink ($absPath);
    }
    if (is_dir($absPath))
    {
        $this->_removeDir ($absPath, $found);
    }
}
if (!$found)
{
    rmdir ($dir);
}
return true;

}

但它在不存在的目录上绊倒

4

0 回答 0