Page 1 of 1

Check if specific folder contains files, folders, both or no

Posted: Fri Feb 26, 2010 7:09 pm
by Peuplarchie
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 :

Code: Select all

 
 
<?PHP
function globDir($dir)
{
   $files = glob("$dir/*", GLOB_ONLYDIR);
   
     if(!empty($files))
   {
      echo "<ul>\n";
 
      foreach($files as $file)
      {
         echo "<li><b>". basename($file)."</b>\n";
         globDir($file);
         echo "</li>\n";
      }
      echo "</ul>\n";
   }
}
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!

Re: Check if specific folder contains files, folders, both or no

Posted: Fri Feb 26, 2010 10:37 pm
by s.dot
1. Check folders to see if they have contents besides '.' and '..'.
1.a See example #2 here.

2. While looping, use is_dir() and is_file() to check if the contents are folders or files.
2.a is_dir() and is_file() can act screwy on windows.