Delicious Bookmark this on Delicious Share on Facebook SlashdotSlashdot It! Digg! Digg



PHP : Function Reference : Standard PHP Library (SPL) Functions : DirectoryIterator::isFile

DirectoryIterator::isFile

Returns true if file is a regular file ()
bool DirectoryIterator::isFile ( )


Code Examples / Notes » directoryiterator_isfile

philipp w. gnurepublic_at_linuxmail.org

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

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 . "
\n";
   }
}


Change Language


Follow Navioo On Twitter
ArrayIterator::current
ArrayIterator::key
ArrayIterator::next
ArrayIterator::rewind
ArrayIterator::seek
ArrayIterator::valid
ArrayObject::append
ArrayObject::__construct
ArrayObject::count
ArrayObject::getIterator
ArrayObject::offsetExists
ArrayObject::offsetGet
ArrayObject::offsetSet
ArrayObject::offsetUnset
CachingIterator::hasNext
CachingIterator::next
CachingIterator::rewind
CachingIterator::__toString
CachingIterator::valid
CachingRecursiveIterator::getChildren
CachingRecursiveIterator::hasChildren
DirectoryIterator::__construct
DirectoryIterator::current
DirectoryIterator::getATime
DirectoryIterator::getCTime
DirectoryIterator::getFilename
DirectoryIterator::getGroup
DirectoryIterator::getInode
DirectoryIterator::getMTime
DirectoryIterator::getOwner
DirectoryIterator::getPath
DirectoryIterator::getPathname
DirectoryIterator::getPerms
DirectoryIterator::getSize
DirectoryIterator::getType
DirectoryIterator::isDir
DirectoryIterator::isDot
DirectoryIterator::isExecutable
DirectoryIterator::isFile
DirectoryIterator::isLink
DirectoryIterator::isReadable
DirectoryIterator::isWritable
DirectoryIterator::key
DirectoryIterator::next
DirectoryIterator::rewind
DirectoryIterator::valid
FilterIterator::current
FilterIterator::getInnerIterator
FilterIterator::key
FilterIterator::next
FilterIterator::rewind
FilterIterator::valid
LimitIterator::getPosition
LimitIterator::next
LimitIterator::rewind
LimitIterator::seek
LimitIterator::valid
ParentIterator::getChildren
ParentIterator::hasChildren
ParentIterator::next
ParentIterator::rewind
RecursiveDirectoryIterator::getChildren
RecursiveDirectoryIterator::hasChildren
RecursiveDirectoryIterator::key
RecursiveDirectoryIterator::next
RecursiveDirectoryIterator::rewind
RecursiveIteratorIterator::current
RecursiveIteratorIterator::getDepth
RecursiveIteratorIterator::getSubIterator
RecursiveIteratorIterator::key
RecursiveIteratorIterator::next
RecursiveIteratorIterator::rewind
RecursiveIteratorIterator::valid
SimpleXMLIterator::current
SimpleXMLIterator::getChildren
SimpleXMLIterator::hasChildren
SimpleXMLIterator::key
SimpleXMLIterator::next
SimpleXMLIterator::rewind
SimpleXMLIterator::valid
class_implements
class_parents
iterator_count
iterator_to_array
spl_autoload_call
spl_autoload_extensions
spl_autoload_functions
spl_autoload_register
spl_autoload_unregister
spl_autoload
spl_classes
spl_object_hash
eXTReMe Tracker