Add item count for folders
This commit is contained in:
@@ -193,6 +193,7 @@ class Crawler
|
||||
'children' => false,
|
||||
'treesize' => 1,
|
||||
'isdir' => $isDir,
|
||||
'childcount' => $isDir ? $this->countDirectChildren($filepath) : 0,
|
||||
];
|
||||
|
||||
$result[] = $entry;
|
||||
@@ -201,6 +202,32 @@ class Crawler
|
||||
return $this->sortItems($result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Count the direct children (files and subdirectories) of a directory.
|
||||
*
|
||||
* Hidden files (starting with '.') are excluded.
|
||||
*
|
||||
* @param string $dirPath
|
||||
* @return int
|
||||
*/
|
||||
protected function countDirectChildren(string $dirPath): int
|
||||
{
|
||||
if (($dir = @opendir($dirPath)) === false) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
$count = 0;
|
||||
while (($file = readdir($dir)) !== false) {
|
||||
// Skip hidden files and special entries
|
||||
if ($file[0] === '.') {
|
||||
continue;
|
||||
}
|
||||
$count++;
|
||||
}
|
||||
closedir($dir);
|
||||
return $count;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sort the given items by the current sortby and sortreverse settings
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user