note 12657 deleted from function.opendir by jimw

From: Date: Sat, 08 Dec 2001 23:43:34 +0000
Subject: note 12657 deleted from function.opendir by jimw
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-22365@lists.php.net to get a copy of this message
Here's a quick routine to read a directory... optionally recurses into subdirectories... // this directory returns all files in the passed directory - it's recursive, too! function list_dir($dirname, $recursive = 1) { // try to figure out what delimeter is that's already in use... $delim = (strstr($dirname,"/")) ? "/" : "\\"; if($dirname[strlen($dirname)-1]!=$delim) $dirname.=$delim; $handle = opendir($dirname); while ($file = readdir($handle)) { if($file=='.'||$file=='..') continue; if(is_dir($dirname.$file) && $recursive) { $x = list_dir($dirname.$file.$delim); $result_array = array_merge($result_array, $x); } else { $result_array[]=$dirname.$file; } } closedir($handle); if (sizeof($result_array)) { natsort($result_array); } return $result_array; }

« previous php.notes (#22365) next »