The TRUE recursive map function for working with dirs & files.
You can create, read(find), update(or move) or delete files/dirs/tree by your callable function.
You can use flags for select what content you need.
<?php
var_dump(dirmap($dst, function($v) {
pre($v);
return true;
}, 1|2|4|8));
function dirmap(string $path, Callable $action, int $flags = 15) {
$flF = boolval($flags & 1);
$flD = boolval($flags & 2);
$flP = boolval($flags & 4);
$flR = boolval($flags & 8);
$result = 1;
if (is_dir($path)) {
$dir = opendir($path);
while ($entry = readdir($dir))
if (!in_array($entry, ['.', '..'])) {
$fullEntry = "{$path}/{$entry}";
if ($flR)
$result &= dirmap($fullEntry, $action, $flags & 11);
if ($flF && is_file($fullEntry) || $flD && is_dir($fullEntry))
$result &= (bool)call_user_func($action, $fullEntry);
}
if ($flP)
$result &= (bool)call_user_func($action, $fullEntry);
return (bool)$result;
} else
return is_file($path);
}
?>