note 93761 deleted from function.opendir by danbrown

From: Date: Sat, 26 Sep 2009 22:54:34 +0000
Subject: note 93761 deleted from function.opendir by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-161101@lists.php.net to get a copy of this message
Note Submitter: izaakstern at hotmail dot com ---- @ james: I think your code is wrong. the recursive mode ends in a endless loop because you recursive call the function with the same arguments. After changing that it does not return an array of strings but an array of strings of the files in the base dir and arrays of strings of the sub directories. i corrected it: function file_array($path, $exclude = ".|..", $recursive = true) { $path = rtrim($path, "/") . "/"; $folder_handle = @opendir($path); $exclude_array = explode("|", $exclude); $result = array(); while ($filename = readdir($folder_handle)) { if(!in_array(strtolower($filename), $exclude_array)) { if(is_dir($path . $filename . "/")) { echo $filename; if($recursive) $result = array_merge($result, file_array($path . $filename, $exclude, true)); } else $result[] = $filename; } } return $result; }

« previous php.notes (#161101) next »