Directory functions Directories For related functions such as dirname, is_dir, mkdir, and rmdir, see the Filesystem section. chroot change the root directory Description boolchroot stringdirectory 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 boolchdir stringdirectory Changes PHP's current directory to directory. Returns &false; if unable to change directory, &true; otherwise. dir directory class Description dir dir stringdirectory stringpath stringread voidrewind voidclose 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. Please note the fashion in which dir's return value is checked in the example below. We are explicitly testing whether the return value is identical to (equal to and of the same type as--see Comparison Operators for more information) &false; since otherwise, any directory entry whose name evaluates to &false; will stop the loop. <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. This defines the internal class Directory, meaning that you will not be able to define your own classes with that name. For a full list of predefined classes in PHP, please see Predefined Classes.
closedir close directory handle Description voidclosedir resourcedir_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 stringgetcwd Returns the current working directory. opendir open directory handle Description resourceopendir stringpath 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 ]]> See also is_dir. readdir read entry from directory handle Description stringreaddir resourcedir_handle Returns the filename of the next file from the directory. The filenames are returned in the order in which they are stored by the filesystem. Please note the fashion in which readdir's return value is checked in the examples below. We are explicitly testing whether the return value is identical to (equal to and of the same type as--see Comparison Operators for more information) &false; since otherwise, any directory entry whose name evaluates to &false; will stop the loop. List all files in a 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> ]]> See also is_dir. rewinddir rewind directory handle Description voidrewinddir resourcedir_handle Resets the directory stream indicated by dir_handle to the beginning of the directory.