文件夹是否为空

1:
function   isEmptyDir(   $path   ) 
{ 
        $dh=   opendir(   $path   ); 
        while(false   !==   ($f   =   readdir($dh))) 
        { 
              if($f   !=   ". "   &&   $f   !=   ".. "   ) 
                    return   true; 
        } 
        return   false; 
}




2:
$root = dirname(__FILE__);
$root = str_replace("\\", "/", $root);
$path = $root.'/test/';

$isempty = file_exit();

//检查目录是否为空
function file_exit($filelastname = ''){

global $path;
if($filelastname != ''){
   $handle = opendir($path.$filelastname);
}else{
   $handle = opendir($path); 
}
while (false !== ($file = readdir($handle))) {
   if($file == '.' || $file == '..'){
    continue;
   }
   $file_array[] = $file;
}
if($file_array == NULL){//没有文件
   closedir($handle);
   return false;
}
closedir($handle);
return true;//有文件
}

猜你喜欢

转载自panyongzheng.iteye.com/blog/1169053