PHP Classes

File: DirectoryIterator.php

Recommend this page to a friend!
  Classes of J.B.   Simple Object   DirectoryIterator.php   Download  
File: DirectoryIterator.php
Role: Auxiliary script
Content type: text/plain
Description: class DirectoryIterator extends SimpleIterator
Class: Simple Object
Base class with common variable access functions
Author: By
Last change:
Date: 20 years ago
Size: 668 bytes
 

Contents

Class file image Download
<?php
   
class DirectoryIterator extends SimpleIterator {
       
        var
$dir_path;
        var
$dir_handle;
       
        function
DirectoryIterator($dir_path) {
           
parent::SimpleIterator(SO_STRICT);
           
$this->init('name');
           
$this->dir_handle = opendir($this->dir_path);
        }
       
        function
next() {
           
$elem_name = readdir($this->dir_handle);
            if (
$elem_name !== FALSE ) {
               
$this->set('name',$elem_name);
                return
TRUE;
            } else {
                return
FALSE;
            }
        }
       
        function
reset() {
           
rewind($this->dir_handle);
        }
       
        function
size() {
           
$this->reset();
           
$size = 0;
            while (
$this->next() ) {
               
$size++;
            }
            return
$size;
        }
    }
?>