windows平台下rmdir Permission denied 错误
function delFile($delList, $deleteRootToo){
if(is_dir($delList)){
@chmod($delList, 0777);
if(!$dh = @opendir($delList)){
return false;
}
while (false !== ($file = readdir($dh))) {
if($file == '.' || $file == '..') continue;
if(is_file($delList.'/'.$file)){
@unlink($delList.'/'.$file);
}else{
$this->delFile($delList.'/'.$file, $deleteRootToo);
}
if($deleteRootToo) rmdir($delList);
}
}else if(is_file($delList)){
@unlink($delList);
}else{
return false;
}
closedir($dh);
return true;
}
今天写了个文件操作类 其中一个删除文件和文件夹的函数每次都报错,经过检查,只要将rmdir($delList);这个放在关闭文件句柄后就正常了
正确函数:
function delFile($delList, $deleteRootToo){
if(is_dir($delList)){
@chmod($delList, 0777);
if(!$dh = @opendir($delList)){
return false;
}
while (false !== ($file = readdir($dh))) {
if($file == '.' || $file == '..') continue;
if(is_file($delList.'/'.$file)){
@unlink($delList.'/'.$file);
}else{
$this->delFile($delList.'/'.$file, $deleteRootToo);
}
}
}else if(is_file($delList)){
@unlink($delList);
}else{
return false;
}
closedir($dh);
if($deleteRootToo) rmdir($delList);
return true;
}