Directory functionsDirectories
For related functions such as dirname,
is_dir, mkdir, and
rmdir, see the
Filesystem section.
chrootchange the root directoryDescriptionbool chrootstring directory
Changes the root directory of the current process to
directory. Returns &false; if unable to
change the root directory, &true; otherwise.
It's not wise to use this function when running in a webserver
environment, because it's not possible to reset the root
directory to / again at the end of the request. This function
will only function correct when running as CGI this way.
chdirchange directoryDescriptionbool chdirstring directory
Changes PHP's current directory to
directory. Returns &false; if unable to
change directory, &true; otherwise.
dirdirectory classDescriptionobject dirstring directory
A pseudo-object oriented mechanism for reading a directory. The
given directory is opened. Two properties
are available once the directory has been opened. The handle
property can be used with other directory functions such as
readdir, rewinddir and
closedir. The path property is set to path
the directory that was opened. Three methods are available:
read, rewind and close.
dir example
handle." \n";
echo "Path: ".$d->path." \n";
while (false !== ($entry = $d->read())) {
echo $entry." \n";
}
$d->close();
]]>
The order in which directory entries are returned by the read method is
system-dependent.
closedirclose directory handleDescriptionvoid closedirresource dir_handle
Closes the directory stream indicated by
dir_handle. The stream must have previously
been opened by opendir.
getcwdgets the current working directoryDescriptionstring getcwd
Returns the current working directory.
opendiropen directory handleDescriptionresource opendirstring path
Returns a directory handle to be used in subsequent
closedir, readdir, and
rewinddir calls.
If path is not a valid directory or the
directory can not be opened due to permission restrictions or
filesystem errors, opendir returns &false; and
generates a PHP error. You can suppress the error output of
opendir by prepending `@' to the front of
the function name.
opendir example
]]>
readdirread entry from directory handleDescriptionstring readdirresource dir_handle
Returns the filename of the next file from the directory. The
filenames are not returned in any particular order.
List all files in the current directory
]]>
Note that readdir will return the .
and
.. entries. If you don't want these, simply strip
them out:
List all files in the current directory and strip out .
and ..
]]>
rewinddirrewind directory handleDescriptionvoid rewinddirresource dir_handle
Resets the directory stream indicated by
dir_handle to the beginning of the
directory.