RosettaCodeData/Task/Empty-directory/PHP/empty-directory.php
Ingy döt Net 764da6cbbb CDE
2013-04-10 16:57:12 -07:00

16 lines
414 B
PHP

$dir = 'path_here';
if(is_dir($dir)){
//scandir grabs the contents of a directory and array_diff is being used to filter out .. and .
$list = array_diff(scandir($dir), array('..', '.'));
//now we can just use empty to check if the variable has any contents regardless of it's type
if(empty($list)){
echo 'dir is empty';
}
else{
echo 'dir is not empty';
}
}
else{
echo 'not a directory';
}