note 34563 rejected from function.readdir by didou

From: Date: Thu, 14 Aug 2003 07:02:45 +0000
Subject: note 34563 rejected from function.readdir by didou
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-54129@lists.php.net to get a copy of this message
Note Submitter: ftrudeau _AT_ zesolution _DOT_ com ---- I really liked the little script posted at 04-Jan-2003 04:34. Problem is, I needed it to be able to search for dirrectories also. See here we are ... the equivalent of find $path -type f, find $path -type d or a merge of both ... Hope it pleases someone else then me =) $files = walk_dir($path, 'files'); $dirs = walk_dir($path, 'dirs'); $both = walk_dir($path, 'both'); function walk_dir($path, $get = 'both') { if ($dir = opendir($path)) { while (false !== ($file = readdir($dir))) { if (is_dir($path . '/' . $file) && ($file != '.') && ($file != '..')) { if ($get == 'dirs' || $get == 'both') { $retval[] = $path . '/' . $file; } $retval = array_merge($retval, walk_dir($path . '/' . $file)); } else if (is_file($path . '/' . $file)) { if ($get == 'files' || $get == 'both') { $retval[] = $path . '/' . $file; } } } closedir($dir); } return $retval; }

« previous php.notes (#54129) next »