note 64539 deleted from function.opendir by bjori
| From: | bjori@php.net | Date: | Tue, 18 Apr 2006 07:45:22 +0000 |
| Subject: | note 64539 deleted from function.opendir by bjori | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-108375@lists.php.net to get a copy of this message | ||
Note Submitter: aaxc at latgolf dot lv
Reason: bad code
----
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.