downloads | documentation | faq | getting help | mailing lists | licenses | wiki | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

DirectoryIterator::isLink> <DirectoryIterator::isExecutable
Last updated: Wed, 22 Jul 2009

view this page in

DirectoryIterator::isFile

(PHP 5 <= 5.1.1)

DirectoryIterator::isFile — Returns true if file is a regular file

Description

bool DirectoryIterator::isFile ( void )
Warning

This function is currently not documented; only the argument list is available.



add a note add a note User Contributed Notes
DirectoryIterator::isFile
Philipp W. gnurepublic_at_linuxmail.org
30-Jul-2007 11:49
to actually sort a directoryiterator you need to subclass the iterator and use a comparator function similar to this one

<?php
function cmpSPLFileInfo( $splFileInfo1, $splFileInfo2 )
{
    return
strcmp( $splFileInfo1->getFileName(), $splFileInfo2->getFileName() );
}

class
DirList extends RecursiveDirectoryIterator
{
    private
$dirArray;

    public function
__construct( $p )
    {
       
parent::__construct( $p );
       
$this->dirArray = new ArrayObject();
        foreach(
$this as $item )
        {
           
$this->dirArray->append( $item );
        }
       
$this->dirArray->uasort( "cmpSPLFileInfo" );
    }

    public function
getIterator()
    {
        return
$this->dirArray->getIterator();
    }

}
?>
DieselDriver at edu dot uni-klu dot ac dot at
24-Apr-2007 05:17
shows all .jpg files in the current directory but how does the DirectoryIterator sort the output!?

$dir=new DirectoryIterator("./");
foreach ($dir as $file) {
  if ($dir->isDot()) {continue;}    //removes . and ..
    if (strripos($file,".jpg")==true) {
      echo $file . "<br>\n";
    }
 }

 
show source | credits | stats | sitemap | contact | advertising | mirror sites