note 93761 added to function.opendir

From: Date: Sat, 26 Sep 2009 22:10:16 +0000
Subject: note 93761 added to function.opendir
Groups: php.notes 
Request: Send a blank email to php-notes+get-161099@lists.php.net to get a copy of this message
@ 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; } ---- Server IP: 212.124.37.9 Probable Submitter: 88.75.58.71 ---- Manual Page -- http://www.php.net/manual/en/function.opendir.php Edit -- https://master.php.net/note/edit/93761 Del: integrated -- https://master.php.net/note/delete/93761/integrated Del: useless -- https://master.php.net/note/delete/93761/useless Del: bad code -- https://master.php.net/note/delete/93761/bad+code Del: spam -- https://master.php.net/note/delete/93761/spam Del: non-english -- https://master.php.net/note/delete/93761/non-english Del: in docs -- https://master.php.net/note/delete/93761/in+docs Del: other reasons-- https://master.php.net/note/delete/93761 Reject -- https://master.php.net/note/reject/93761 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#161099) next »