opendir
opendir
Open directory handle
**opendir** string $directory $context
Opens up a directory handle to be used in subsequent
, , and
calls.
closedir``readdir``rewinddir
directoryThe directory path to open.
context
For a description of the parameter,
refer to of
the manual.
contextthe streams section
Returns a directory handle on success, return.falseforfailure
This may happen if is not a valid directory,
the directory can not be opened due to permission restrictions,
or due to filesystem errors.
directory
**Voorbeeld: List all entries in a directory, skipping the special and directories **
Because file and directory names can be strings that PHP considers "falsy"
(e.g. a directory named ) and
returns false when it has read all entries
in a directory one needs to use the
to properly distinguish between a directory entry whose name is "falsy"
and having read all entries of the directory.
"0"``readdir``===comparison operator
<?php
if ($handle = opendir('/path/to/files')) {
echo "Entries:\n";
/* Correctly handling directory entries that may be considered falsy */
while (false !== ($entry = readdir($handle))) {
if ($entry === '.' || $entry === '..') {
continue;
}
echo "$entry\n";
}
closedir($handle);
}
?>
Entries:
base
en
fr
output.md
test.php
readdir``rewinddir``closedir``dir``is_dir``glob``scandir