Directory functions Directories For related functions such as dirname, is_dir, mkdir, and rmdir, see the Filesystem section. chroot change the root directory Description bool chroot string 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. chdir change directory Description bool chdir string directory Changes PHP's current directory to directory. Returns &false; if unable to change directory, &true; otherwise. dir directory class Description object dir string 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. <function>dir</function> 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.
closedir close directory handle Description void closedir resource dir_handle Closes the directory stream indicated by dir_handle. The stream must have previously been opened by opendir. getcwd gets the current working directory Description string getcwd Returns the current working directory. opendir open directory handle Description resource opendir string 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. <function>opendir</function> example ]]> readdir read entry from directory handle Description string readdir resource 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 <literal>.</literal> and <literal>..</literal> ]]> rewinddir rewind directory handle Description void rewinddir resource dir_handle Resets the directory stream indicated by dir_handle to the beginning of the directory.