Re: DirectoryIterator

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tue, Jan 26, 2010 at 1:25 PM, Christoph Boget <cboget@xxxxxxxxxxx> wrote:

> >
> > def not on DirectorIterator afaik, and furthermore, i dont think thats
> > supported at the shell / filesystem level even.
>
>
> Well if the Iterator has the whole of the collection in order to be able to
> iterate over it, I would think that it should be able to return the size of
> that collection... :(
>

right but the collection is built during iteration.  one thing you could do
if you wanted it to *appear* as though the count was there at construction
is to subclass and iterate once in the constructor.

something like this:

<?php
class SmartDirectoryIterator extends DirectoryIterator implements Countable
{
  private $_iCount = 0;

  public function __construct($sPath)
  {
    parent::__construct($sPath);
    foreach($this as $oFile)
      if($oFile->isFile())
        $this->_iCount++;
  }

  public function count()
  {
    return $this->_iCount;
  }
?>

-nathan

[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux