dir = $dir; $this->files = $this->read_dir(); } // extract directories from $dir // returns fullpath for each entries. function subdirs(){ $list = array(); foreach($this->files as $file){ if(is_dir($file)) { if(preg_match("/\.\.$/", $file)) continue; if(preg_match("/\.$/", $file)) continue; array_push($list, $file); } } return($list); } // extract files from $dir function files($spec = ""){ $list = array(); foreach($this->files as $file){ if($spec == "") { if(!is_dir($file)) { array_push($list, $file); } } else { if(!is_dir($file) && preg_match($spec, basename($file))) { array_push($list, $file); } } } return($list); } // private - read $this->dir // remove .. and .. // function read_dir(){ $handle = opendir($this->dir) or die ("can't open dir : $this->dir"); $list = array(); /* This is the correct way to loop over the directory. */ while (false !== ($file = readdir($handle))) { if(preg_match("#/$#", $this->dir)) $f = $this->dir . $file; else $f = $this->dir . "/" . $file; array_push($list, $f); } return($list); } } ?>