Friday Nov 13, 2009
Little-known PHP commands: scandir()
Always messed around with a combo of opendir(), readdir(), and closedir() if you wanted to read the contents of a directory? Since PHP 5 there is a new sheriff in town: scandir():
<?php
$files=scandir("/etc/php5");
print_r($files);
?>
Outputs:
Array
(
[0] => .
[1] => ..
[2] => apache2
[3] => conf.d
)
Okay, you still need to traverse an array, but it's much easier to use than the traditional way.