main folder is home
– with subfolders and txt
files – on various levels
I need the list of entire folders tree – and count txt
files inside each of them
This code gives the folders but count is always – 0
I suppose paths to folders
and not only folder names – are required, but can’t see – how to get them.
function rscan ($dir) {
$all = array_diff(scandir($dir), [".", ".."]);
foreach ($all as $ff) {
if(is_dir($dir . $ff)){
echo $ff . "n"; // it works
$arr = glob($ff . "/*.txt");
echo count($arr) . "n"; // always 0
rscan("$dir$ff/");
}
}
}
rscan("home/");
2
Answers
Line 6
Change to the code below:
An alternate implementation:
The output is something like: