note 64539 added to function.opendir
| From: | aaxc at latgolf dot lv | Date: | Tue, 18 Apr 2006 06:57:50 +0000 |
| Subject: | note 64539 added to function.opendir | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-108372@lists.php.net to get a copy of this message | ||
To get only the file list or the directory list in a certain directory, you can easely use these two
functions:
Function DirList($dir) {
$dh = opendir($dir);
while (false !== ($filename = readdir($dh))) {
$files[] = $filename;
}
sort($files);
for ($i=2; $i<=sizeof($files)-1; $i++) {
if (is_file($dir.$files[$i]) == false) {
$liste[] = $files[$i];
}
}
return $liste;
}
Function FileList($dir) {
$dh = opendir($dir);
while (false !== ($filename = readdir($dh))) {
$files[] = $filename;
}
sort($files);
for ($i=2; $i<=sizeof($files)-1; $i++) {
if (is_file($dir.$files[$i]) == true) {
$liste[] = $files[$i];
}
}
return $liste;
}
The 1st function returns an array with only the directories listed in you desired dir and the 2nd
function returns an array with only the files listed. Have fun with it.
----
Server IP: 81.94.227.69
Probable Submitter: 80.232.239.2
----
X-Spam-Status: No, hits=3.1 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER
autolearn=no version=2.64
----
Manual Page -- http://www.php.net/manual/en/function.opendir.php
Edit -- http://master.php.net/note/edit/64539
Del: integrated -- http://master.php.net/note/delete/64539/integrated
Del: useless -- http://master.php.net/note/delete/64539/useless
Del: bad code -- http://master.php.net/note/delete/64539/bad+code
Del: spam -- http://master.php.net/note/delete/64539/spam
Del: non-english -- http://master.php.net/note/delete/64539/non-english
Del: in docs -- http://master.php.net/note/delete/64539/in+docs
Del: other reasons-- http://master.php.net/note/delete/64539
Reject -- http://master.php.net/note/reject/64539
Search -- http://master.php.net/manage/user-notes.php