note 44477 deleted from function.is-dir by tomsommer

From: Date: Sat, 07 Aug 2004 04:22:26 +0000
Subject: note 44477 deleted from function.is-dir by tomsommer
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-74132@lists.php.net to get a copy of this message
Note Submitter: ewillems (at) reflexlight (dot) nl ---- The strange behavor isn't strange! readdir() gives just the filenames, not the full path. Adding $dir to the is_dir() check would fix the problem. To remove the . and .. from the list, you could add ($filename!="..") && ($filename!=".") to the check. Full example: <?php ### dirlist.php ### //---------------------------------------------------- function get_dirlist($dir) { $dirlist=array(); $dh=opendir($dir); if ($dh) { while ($filename=readdir($dh)) { if (is_dir($dir.$filename) && ($filename!="..") && ($filename!=".")) { $dirlist[]=$filename; } } closedir($dh); } else { // ggf. Fehlermeldung setzen return false; } asort($dirlist); return $dirlist; } //----------------------------------------------------- $dir = get_dirlist(".."); echo "<pre>"; print_r($dir); echo "</pre>"; ?>

« previous php.notes (#74132) next »