PHP.nl

scandir

scandir

List files and directories inside the specified path

 **scandir** string $directory int $sorting_order  $context

Returns an of files and directories from the . array``directory

directoryThe directory that will be scanned.

sorting_order By default, the sorted order is alphabetical in ascending order. If the optional is set to , then the sort order is alphabetical in descending order. If it is set to then the result is unsorted. sorting_order``SCANDIR_SORT_DESCENDING``SCANDIR_SORT_NONE

context For a description of the parameter, refer to of the manual. contextthe streams section

Returns an of filenames on success, or false on failure. If is not a directory, then boolean false is returned, and an error of level is generated. array``directory``E_WARNING

Voorbeeld: A simple example

<?php
$dir    = '/tmp';
$files1 = scandir($dir);
$files2 = scandir($dir, SCANDIR_SORT_DESCENDING);

print_r($files1);
print_r($files2);
?>
Array
(
    [0] => .
    [1] => ..
    [2] => bar.php
    [3] => foo.txt
    [4] => somedir
)
Array
(
    [0] => somedir
    [1] => foo.txt
    [2] => bar.php
    [3] => ..
    [4] => .
)

opendir``readdir``glob``is_dir``sort