dir

Return an instance of the Directory class

Syntax

dir(string $directory, ?resource $context = null): Directory|false

Parameters

directory

Directory to open

context

A context stream resource.

Return

Returns an instance of Directory, or false in case of error.

Examples

1 · directory

<?

$directory = ".";

$return = dir($directory);

print_r($return);

?>
Directory Object
(
    [path] => .
    [handle] => Resource id #3
)

2 · context

<?

$directory = ".";
$context = stream_context_create();

$return = dir($directory, $context);

print_r($return);

?>
Directory Object
(
    [path] => .
    [handle] => Resource id #3
)

3 · read

<?

$directory = ".";

$return = dir($directory);

echo "path: $return->path\n";
echo "handle: $return->handle\n\n";

while(($read = $return->read()) !== false)
{
    echo "$read\n";
}
$return->close();

?>
path: .
handle: Resource id #3

index.php
..
.

chdir

chroot

closedir

getcwd

opendir

readdir

rewinddir

scandir

PHP

Home Menu