redhat.com
DirectoryIterator
Another very interesting class introduced in PHP5 is DirectoryIterator. This
object can iterate through the items present in a directory (well, those nothing but
files) and you can retrieve different attributes of that file using this object.
In the PHP Manual this object is not well documented. So if you want to know
the structure of this object and supported methods and properties, you can use
ReflectionClass for that. Remember the ReflectionClass we used in the
previous chapter? Let's take a look at the following example:
ReflectionClass::export(DirectoryIterator);
?>
The result is:
Class [
class DirectoryIterator
implements Iterator, Traversable ]
{
- Constants [0] { }
- Static properties [0] { }
- Static methods [0] { }
- Properties [0] { }
- Methods [27]
{
Method [ public method __construct ]
{
- Parameters [1]
{
Standard PHP Library
[ 150 ]
Parameter #0 [ $path ]
}
}
Method [ public method rewind ] { }
Method [ public method valid ] { }
Method [ public method key ] { }
Method [ public method current ] { }
Method [ public method next ] { }
Method [ public method getPath ] { }
Method [ public method getFilename ] { }
Method [ public method getPathname ] { }
Method [ public method getPerms ] { }
Method [ public method getInode ] { }
Method [ public method getSize ] { }
Method [ public method getOwner ] { }
Method [ public method getGroup ] { }
Method [ public method getATime ] { }
Method [ public method getMTime ] { }
Method [ public method getCTime ] { }
Method [ public method getType ] { }
Method [ public method isWritable ] { }
Method [ public method isReadable ] { }
Method [ public method isExecutable ] { }
Method [ public method isFile ] { }
Method [ public method isDir ] { }
Method [ public method isLink ] { }
Method [ public method isDot ] { }
Method [ public method openFile ]
{
- Parameters [3] {
Parameter #0 [ $open_mode ]
Parameter #1 [ $use_include_path ]
Parameter #2 [ $context ]
}
}
Method [ public method __toString ] { }
}
}
We have a handful of useful methods here.
Pages:
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167