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;//有文件 }