background image

*/
function blist($path){
if(!is_dir(iconv("utf-8","gbk",$path))){
throw new Exception("文件夹".$path."不存在或者不是文件");
}
$arr = array();
$hd = opendir(iconv("utf-8","gbk",$path));
while(($file = readdir($hd))!==false){
if($file=="."||$file=="..") {continue;}
$newpath=iconv('utf-8', 'gbk', $path) .'/'.$file;
if(is_dir($newpath)){
$arr[] = blist($path."/".$file);
}else if(is_file($newpath)){
$arr[] = iconv('gbk','utf-8',$file);
}
}
closedir($hd);
return $arr;
}

/**
* 删除目录下的文件以及子目录
* #param string $path 路径
* #return string 删除成功返回 true 失败返回 false;
*/
function dirDel($path){
if(!is_dir($path)){
throw new Exception($path."输入的不是有效目录");
}
$hand = opendir($path);
while(($file = readdir($hand))!==false){
if($file=="."||$file=="..") continue;
if(is_dir($path."/".$file)){
dirDel($path."/".$file);
}else{
@unlink($path."/".$file);
}

}
closedir($hand);
@rmdir($path);
}
?>