note 44477 added to function.is-dir

From: Date: Sat, 07 Aug 2004 04:18:32 +0000
Subject: note 44477 added to function.is-dir
Groups: php.notes 
Request: Send a blank email to php-notes+get-74128@lists.php.net to get a copy of this message
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>"; ?> ---- Manual Page -- http://www.php.net/manual/en/function.is-dir.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+44477 Delete -- http://master.php.net/manage/user-notes.php?action=delete+44477&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+44477&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#74128) next »