Code: Select all
function process_directory($dir_name,$func_name,$max_depth = 10,$depth = 0,$func_var) {
if ($depth >= $max_depth) {
error_log("Reached max depth $max_depth in $dir_name\.");
return false;
}
$subdirectories = array();
$files = array();
if (is_dir($dir_name) && is_readable($dir_name)) {
$d = dir($dir_name);
while (false !== ($f = $d->read())) {
// skip . and ..
if (('.' == $f) || ('..' == $f)) {
continue;
}
` if (is_dir("$dir_name/$f")) {
array_push($subdirectories,"$dir_name/$f");
} else {
$func_name("$dir_name/$f","$func_var");
}
}
$d->close();
foreach ($subdirectories as $subdirectory) {
process_directory($subdirectory,$func_name,$max_depth,$depth+1,$func_var);
}
}
return true;
}