Check if specific folder contains files, folders, both or none?

Good day to you all,
is there a way to check if a specific folder contains: files, folder, both or none ?

I read my folder with Glob, like my code here :



<?PHP
function globDir($dir)
{
   $files = glob("$dir/*", GLOB_ONLYDIR);
   
	 if(!empty($files))
   {
      echo "<ul>\
";

      foreach($files as $file)
      {
         echo "<li><b>". basename($file)."</b>\
";
         globDir($file);
         echo "</li>\
";
      }
      echo "</ul>\
";
   }
}
globDir('Photos');
?>


The only thing I have really found is how to find if a specific file exists.

I’m trying to find out if a specific folder contains : files, folders, both, none.
It would return the appropriate word accordingly.

Thanks and take care!

Quite unusual task. What’s the use of such information?

Though the only way for your answer is to get whole folder contents and loop over it.
or 2 glob() calls, only files and only dirs
I don’t understand your problem.
You already have glob(“$dir/*”, GLOB_ONLYDIR);
so you can tell if there any folders.
add another call for the files and you are set.

To check if only the ‘Photos’ folder contains files and/or folders, you could try the code below.


function globDir($dir)
{
    $files = glob($dir.'/*');
     if(!empty($files))
     {
      echo "The <b>".$dir."</b> folder contains:\
";
      echo "<ul>\
";

      foreach($files as $file)
      {
         $filetype = '';
         $filetype = is_dir($file) ? 'folder' : 'file';

         $file = str_replace($dir.'/', '', $file);

         echo "<li><b>".$file."</b> - ".$filetype."</li>\
";
      }

      echo "</ul>\
";
   } else {
      echo "The <b>".$dir."</b> folder is empty.\
";
   }
}
globDir('Photos');

Nice, but what i’m trying to find out here is whether or not there is file in the folder, if yes write it as a link if no right it in bold.