note 49823 added to function.scandir
| From: | dot) | Date: | Wed, 09 Feb 2005 15:21:04 +0000 |
| Subject: | note 49823 added to function.scandir | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-84719@lists.php.net to get a copy of this message | ||
Here is a scandir() function I wrote for my own using in php 4.3.10.
If the directory doesnt exist, it returns an empty array. If you pass TRUE to the optional second
argument, it will not return "." and ".." in the output array.
Enjoy...
function scandir($dir, $no_dots=FALSE) {
$files = array();
$dh = @opendir($dir);
if ($dh!=FALSE) {
while (false !== ($filename = readdir($dh))) {
$files[] = $filename;
}
sort($files);
if ($no_dots) {
while(($ix = array_search('.',$files)) > -1)
unset($files[$ix]);
while(($ix = array_search('..',$files)) > -1)
unset($files[$ix]);
}
}
return $files;
}
----
Manual Page -- http://www.php.net/manual/en/function.scandir.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+49823
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+49823&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+49823&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+49823&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+49823&report=yes&reason=useless
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+49823&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+49823&report=yes
Search -- http://master.php.net/manage/user-notes.php