setDefaults(); } function setDefaults() { $this->dirFilter = array('/', 'CVS', '.svn'); // Default directory filter (exact matches only) $this->fileFilter = array('^thumbs\.db$','^Thumbs\.db$','.*\._$','^\.htaccess$','^index\.html$','^null\.txt$','\.bak$'); // Default file filter (regex format) } function get_files($path, $fmask = '', $omit='standard', $recurse_level = 0) { $ret = array(); $invert = FALSE; if (substr($fmask,0,1) == '~') { $invert = TRUE; // Invert selection - exclude files which match selection $fmask = substr($fmask,1); } if($recurse_level < 0) { return $ret; } if(substr($path,-1) == '/') { $path = substr($path, 0, -1); } if(!$handle = opendir($path)) { return $ret; } if (($omit == 'standard') || ($omit == '')) { $omit = array(); } else { if (!is_array($omit)) { $omit = array($omit); } } while (false !== ($file = readdir($handle))) { if(is_dir($path.'/'.$file)) { // Its a directory - recurse into it unless a filtered directory or required depth achieved // Must always check for '.' and '..' if(($file != '.') && ($file != '..') && !in_array($file, $this->dirFilter) && !in_array($file, $omit) && ($recurse_level > 0)) { $xx = $this->get_files($path.'/'.$file, $fmask, $omit, $recurse_level - 1); $ret = array_merge($ret,$xx); } } else { // Now check against standard reject list and caller-specified list if (($fmask == '') || ($invert != preg_match("#".$fmask."#", $file))) { // File passes caller's filter here $rejected = FALSE; // Check against the generic file reject filter foreach($this->fileFilter as $rmask) { if(preg_match("#".$rmask."#", $file)) { $rejected = TRUE; break; // continue 2 may well work } } if($rejected == FALSE) { $finfo['path'] = $path."/"; // important: leave this slash here and update other file instead. $finfo['fname'] = $file; $ret[] = $finfo; } } } } return $ret; } // Get a list of directories matching $fmask, omitting any in the $omit array - same calling syntax as get_files() // N.B. - no recursion - just looks in the specified directory. function get_dirs($path, $fmask = '', $omit='standard') { $ret = array(); if(substr($path,-1) == '/') { $path = substr($path, 0, -1); } if(!$handle = opendir($path)) { return $ret; } if($omit == 'standard') { $omit = array(); } else { if (!is_array($omit)) { $omit = array($omit); } } while (false !== ($file = readdir($handle))) { if(is_dir($path.'/'.$file) && ($file != '.') && ($file != '..') && !in_array($file, $this->dirFilter) && !in_array($file, $omit) && ($fmask == '' || preg_match("#".$fmask."#", $file))) { $ret[] = $file; } } return $ret; } // Delete a complete directory tree function rmtree($dir) { if (substr($dir, -1) != '/') { $dir .= '/'; } if ($handle = opendir($dir)) { while ($obj = readdir($handle)) { if ($obj != '.' && $obj != '..') { if (is_dir($dir.$obj)) { if (!$this->rmtree($dir.$obj)) { return false; } } elseif (is_file($dir.$obj)) { if (!unlink($dir.$obj)) { return false; } } } } closedir($handle); if (!@rmdir($dir)) { return false; } return true; } return false; } } ?>