* Recursively scans a directory for subfolders (relative paths). */
(string $dir, string $relative = '')
| 1930 | * Recursively scans a directory for subfolders (relative paths). |
| 1931 | */ |
| 1932 | private static function getSubfolders(string $dir, string $relative = ''): array |
| 1933 | { |
| 1934 | $folders = []; |
| 1935 | $items = @scandir($dir) ?: []; |
| 1936 | $SKIP = FS::SKIP(); |
| 1937 | foreach ($items as $item) { |
| 1938 | if ($item === '.' || $item === '..') { |
| 1939 | continue; |
| 1940 | } |
| 1941 | if ($item === '' || $item[0] === '.') { |
| 1942 | continue; |
| 1943 | } |
| 1944 | if (FS::shouldIgnoreEntry($item, $relative)) { |
| 1945 | continue; |
| 1946 | } |
| 1947 | if (!preg_match(REGEX_FOLDER_NAME, $item)) { |
| 1948 | continue; |
| 1949 | } |
| 1950 | if (in_array(strtolower($item), $SKIP, true)) { |
| 1951 | continue; |
| 1952 | } |
| 1953 | |
| 1954 | $path = $dir . DIRECTORY_SEPARATOR . $item; |
| 1955 | if (is_dir($path)) { |
| 1956 | $folderPath = ($relative ? $relative . '/' : '') . $item; |
| 1957 | $folders[] = $folderPath; |
| 1958 | $folders = array_merge($folders, self::getSubfolders($path, $folderPath)); |
| 1959 | } |
| 1960 | } |
| 1961 | return $folders; |
| 1962 | } |
| 1963 | |
| 1964 | /** |
| 1965 | * Retrieves the list of folders (including "root") along with file count metadata. |
no test coverage detected