private static List<DirId> findDirs(final Path path,
                                        final Mode mode,
                                        final Predicate<Path> pathPredicate) {

        final Comparator<DirId> comparator = switch (mode) {
            case MIN -> DIR_ID_COMPARATOR_ASC;
            case MAX -> DIR_ID_COMPARATOR_DESC;
        };
        LOGGER.trace("findDirs - path: {}, mode: {}", path, mode);
        try (final Stream<Path> dirStream = findDirectories(path)) {
            return dirStream.map(
                            aPath -> {
                                final DirId dirId;
                                final String fileNamePart = aPath.getFileName().toString();

                                if (pathPredicate.test(aPath)) {
                                    // Parse numeric part of dir.
                                    final OptionalLong optNum = parse(fileNamePart);
                                    if (optNum.isPresent()) {
                                        dirId = new DirId(aPath, optNum.getAsLong());
                                    } else {
                                        LOGGER.warn(() -> LogUtil.message(
                                                "Found unexpected non-numeric directory '{}' in '{}' " +
                                                "when looking for the minimum directory ID. " +
                                                "It will be ignored.",
                                                LogUtil.path(aPath), LogUtil.path(path)));
                                        dirId = null;
                                    }
                                } else {
                                    LOGGER.warn(() -> LogUtil.message(
                                            "Found unexpected directory '{}'", LogUtil.path(aPath)));
                                    dirId = null;
                                }
                                return dirId;
                            })
                    .filter(Objects::nonNull)
                    .sorted(comparator)
                    .toList();
        } catch (final IOException e) {
            throw new UncheckedIOException(e);
        }
    }
Get all the directories that are a direct child of path and
that have a valid leaf or branch filename.
Sorted according to mode.
stroom-proxy/stroom-proxy-app/src/main/java/stroom/proxy/app/handler/DirUtil.java