note 37993 deleted from function.is-dir by tomsommer

From: Date: Sat, 07 Aug 2004 04:21:53 +0000
Subject: note 37993 deleted from function.is-dir by tomsommer
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-74129@lists.php.net to get a copy of this message
Note Submitter: tom@bitworks.de ---- I've been asked for improving a function for getting the subdirectories of a directory, perhaps beyond that also as a recursive function. But there occured a strange behavor of "is_dir()" The function as listed below matches the needs. Im quiet a little bit confused aboeut that. <?php ### dirlist.php ### ### Funktion zur Erzeugung einer Directoryliste ### ### irgendwas ist hier buggy. ### //---------------------------------------------------- function get_dirlist($dir) { $dirlist=array(); $dh=opendir($dir); if ($dh) { while ($filename=readdir($dh)) { if (!is_file($filename) and !is_dir($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>"; ?> My PHP Version is 4.3.1 on a Debian Linux Would be glad to get feedback Tom

« previous php.notes (#74129) next »