Re: directory help

From: Date: Mon, 17 Jul 2000 04:17:19 +0000
Subject: Re: directory help
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-6866@lists.php.net to get a copy of this message
On 16 Jul, Jay Hester wrote: > Hi, > I need to recursivly traverse a directory path, anyone have any > ideas on how to do this? I've tried many things, but none have been > successful so far. Thanks! > > Jay > > Here's what I used in one app - there are bound to be better ways function read_files($dirname) { global $filelist; unset($filelist); $dirid = opendir($dirname); while($entry = readdir($dirid)): $this = $dirname . $entry; if ( (is_file($this)) && ($entry != ".") && ($entry != "..") && (strstr($this, ".htm") || strstr($this, ".html"))): $filelist[] = $entry; endif; endwhile; } function exclude_dir($dirname) { global $badwords; $outcome = false; while(list($key, $value) = each($badwords)): if (strstr("$dirname", "$value")): $outcome = true; endif; endwhile; reset($badwords); return $outcome; } function recurse_dir($basedir) { global $dirlist; $dirid = opendir("$basedir"); while ($entry = readdir($dirid) ) { $this = $basedir . $entry; if ( (is_dir($this)) && ($entry != ".") && ($entry != "..") && (!exclude_dir("$this/"))) { $dirlist[] = $this; recurse_dir("$this/"); }; }; }; Badlist is a space separated list of directory names you want to exclude. Call it with recurse_dir("/full/path/tostartpoint") And now I'm going to go look at that and see where I can improve it :-) Cheers -- David Robley | WEBMASTER & Mail List Admin RESEARCH CENTRE FOR INJURY STUDIES | http://www.nisu.flinders.edu.au/ AusEinet | http://auseinet.flinders.edu.au/ Flinders University, ADELAIDE, SOUTH AUSTRALIA

« previous php.general (#6866) next »