private Optional<DirId> findDir(final Path path) {
        try (final Stream<Path> stream = findDirectories(path)) {
            return stream.map(
                            aPath -> {
                                final DirId dirId;
                                // Parse numeric part of dir.
                                final OptionalLong optNum = parse(aPath.getFileName().toString());
                                if (optNum.isPresent()) {
                                    dirId = new DirId(aPath, optNum.getAsLong());
                                } else {
                                    LOGGER.warn(() -> LogUtil.message(
                                            "Found unexpected non-numeric directory '{}' in '{}'. It will be ignored.",
                                            LogUtil.path(aPath), LogUtil.path(parentDir)));
                                    dirId = null;
                                }
                                return dirId;
                            })
                    .filter(Objects::nonNull)
                    .max(DIR_ID_COMPARATOR);
        } catch (final IOException e) {
            throw new UncheckedIOException(e);
        }
    }
Get the {@link DirId} with the highest {@link DirId#num}. Ignores files and non-numeric dirs.
stroom-proxy/stroom-proxy-app/src/main/java/stroom/proxy/app/handler/NumberedDirProvider.java