Add item count for folders

This commit is contained in:
2026-01-19 09:38:47 +01:00
parent 8aa022feff
commit d3e087ad6e
2 changed files with 30 additions and 1 deletions

View File

@@ -193,6 +193,7 @@ class Crawler
'children' => false, 'children' => false,
'treesize' => 1, 'treesize' => 1,
'isdir' => $isDir, 'isdir' => $isDir,
'childcount' => $isDir ? $this->countDirectChildren($filepath) : 0,
]; ];
$result[] = $entry; $result[] = $entry;
@@ -201,6 +202,32 @@ class Crawler
return $this->sortItems($result); 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 * Sort the given items by the current sortby and sortreverse settings
* *

View File

@@ -363,7 +363,9 @@ class Output
if ($params['showsize']) { if ($params['showsize']) {
$renderer->tablecell_open(1, 'right'); $renderer->tablecell_open(1, 'right');
if (!empty($item['isdir'])) { if (!empty($item['isdir'])) {
$renderer->cdata(''); // Show item count for directories
$childCount = $item['childcount'] ?? 0;
$renderer->cdata($childCount . ' ' . ($childCount === 1 ? 'item' : 'items'));
} else { } else {
$renderer->cdata(filesize_h($item['size'])); $renderer->cdata(filesize_h($item['size']));
} }