public function current() { return parent::getFileName(); } /*** members are only valid if they are a directory ***/ public function valid() { if (parent::valid()) { if (!parent::isDir()) { parent::next(); return $this->valid(); } return TRUE; } return FALSE; } } // end class try { /*** a new iterator object ***/ $it = new DirectoryReader('./'); /*** loop over the object if valid ***/ while ($it->valid()) { /*** echo the current object member ***/ echo $it->current() . '<br />'; /*** advance the internal pointer ***/ $it->next(); } } catch (Exception $e) { echo 'No files Found!<br />'; }
function __construct($path) { parent::__construct($path); } //Возвращаем текущее имя файла function current() { return parent::getFileName(); } //Нужна только директория function valid() { if (parent::valid()) { if (!parent::isDir()) { parent::next(); return $this->valid(); } return true; } return false; } } try { $it = new DirectoryReader('..'); while ($it->valid()) { echo $it->current() . "\n"; $it->next(); } } catch (Exception $e) { echo 'Файлов в директории нет!'; }