Do not think so. The shortest / fastest way I can think of is the following, which should work as far as I can tell.
function dir_is_empty($path)
{
$empty = true;
$dir = opendir($path);
while($file = readdir($dir))
{
if($file != '.' && $file != '..')
{
$empty = false;
break;
}
}
closedir($dir);
return $empty;
}
This should go through no more than three files. Two .and ..and maybe all that comes next. If something comes next, it is not empty, and if not, then it is empty.
source
share