Directory Functions

Directory Functions

chdir

dir

Name

chdir — change directory

Description

int chdir(string directory);

Changes PHP's current directory to directory. Returns FALSE if unable to change directory, TRUE otherwise.

Name

dir — directory class

Description

new dir(string directory);

A pseudo-object oriented mechanism for reading a directory. The given directory is opened. Two properties are available once 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.

Example 1. Dir() Example

$d = dir("/etc");

echo "Handle: ".$d->handle."<br>\n"; echo "Path: ".$d->path."<br>\n"; while($entry=$d->read()) {

echo $entry."<br>\n";

}

$d->close();

closedir

Name

closedir — close directory handle

Description

void closedir(int dir_handle);

Closes the directory stream indicated by dir_handle. The stream must have previously been opened by opendir.

opendir

Name

opendir — open directory handle

Description

int opendir(string path);

Returns a directory handle to be used in subsequent closedir, readdir, and rewinddir calls.

readdir

Name

readdir — read entry from directory handle

Description

string readdir(int dir_handle);

Returns the filename of the next file from the directory. The filenames are not returned in any particular order.

rewinddir

Name

rewinddir — rewind directory handle

Description

void rewinddir(int dir_handle);

Resets the directory stream indicated by dir_handle to the beginning of the directory.