Re: Directory
| From: | Paul Scott | Date: | Thu, 07 Feb 2008 18:51:35 +0000 |
| Subject: | Re: Directory | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-268893@lists.php.net to get a copy of this message | ||
On Thu, 2008-02-07 at 12:30 -0600, Steve Marquez wrote:
> Could someone please point me in the right direction? I am trying to have
> PHP find out if a directory has files in it and then if it does, display and
> include, if it does not, then not display the include.
oooh, goodie! You get to play with my new favourite toys - SPL!
Try this:
public function lsDir($dir, $type='files')
{
$iterator = new RecursiveDirectoryIterator($dir);
foreach (new RecursiveIteratorIterator($iterator, RecursiveIteratorIterator::CHILD_FIRST) as $file)
{
if ($file->isDir()) {
$dirs[] = $file->getPathname();
} else {
$files[] = $file->getPathname();
}
}
if($type = 'files')
{
return $files;
}
else {
return $dirs;
}
}
(untested - written from mind dump - so please test 1st)
Then, AFAIK SPL also has an __autoload that you can use.
> I have looked at the Manual and did not really know where to look.
>
http://www.php.net/spl
--Paul
--
------------------------------------------------------------.
| Chisimba PHP5 Framework - http://avoir.uwc.ac.za |
:------------------------------------------------------------: