From d3e087ad6ec1a1f364f9c27aca4dabe8aebe529f Mon Sep 17 00:00:00 2001 From: luxick Date: Mon, 19 Jan 2026 09:38:47 +0100 Subject: [PATCH] Add item count for folders --- src/Crawler.php | 27 +++++++++++++++++++++++++++ src/Output.php | 4 +++- 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/src/Crawler.php b/src/Crawler.php index b994fed..75e48ac 100644 --- a/src/Crawler.php +++ b/src/Crawler.php @@ -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 * diff --git a/src/Output.php b/src/Output.php index 6136382..c443e08 100644 --- a/src/Output.php +++ b/src/Output.php @@ -363,7 +363,9 @@ class Output if ($params['showsize']) { $renderer->tablecell_open(1, 'right'); if (!empty($item['isdir'])) { - $renderer->cdata(''); + // Show item count for directories + $childCount = $item['childcount'] ?? 0; + $renderer->cdata($childCount . ' ' . ($childCount === 1 ? 'item' : 'items')); } else { $renderer->cdata(filesize_h($item['size'])); }