public static boolean isValidLeafOrBranchPath(final Path path) {
        if (path == null) {
            return false;
        } else {
            final int nameCount = path.getNameCount();
            final int lastNameIdx = nameCount - 1;
            final String leafPart = path.getName(lastNameIdx).toString();
            final int leafLen = leafPart.length();
            LOGGER.trace("path: {}, nameCount: {}, lastNameIdx: {}, leafPart: {}, leafLen: {}",
                    path, nameCount, lastNameIdx, leafPart, leafLen);
            if (isValidDepthPart(leafPart)) {
                // The depth part
                return true;
            } else {
                final boolean isValidLeafPart = isValidLeafPath(path);
                if (isValidLeafPart) {
                    return true;
                } else {
                    boolean foundDepthPart = false;
                    int depth = -1;
                    int branchPartCount = 0;
                    for (int i = lastNameIdx; i >= 0; i--) {
                        final String part = path.getName(i).toString();
                        if (isValidDepthPart(part)) {
                            depth = (int) parse(part)
                                    .orElse(-1);
                            if (depth != -1) {
                                foundDepthPart = true;
                            } else {
                                return false;
                            }
                            break;
                        } else if (isValidBranchPart(part)) {
                            branchPartCount++;
                        } else {
                            return false;
                        }
                    }
                    if (foundDepthPart) {
                        // If we are in here then the path is NOT a valid leaf path, so
                        // number of branch parts must be less than or equal to the depth
                        // e.g.
                        // /0/ OK
                        // /1/123 OK
                        // /1/123/456 NOT OK
                        return branchPartCount <= depth;
                    } else {
                        return false;
                    }
                }
            }
        }
    }
Paths would be one of these (assuming a leaf path of '....../2/333/555/333555777')
<ul>
    <li>{@code .../2/}</li>
    <li>{@code .../2/333/}</li>
    <li>{@code .../2/333/555}</li>
    <li>{@code .../2/333/333555777}</li>
</ul>

@return True if the path conforms to the expected dir structure.
stroom-state/stroom-planb-impl/src/main/java/stroom/planb/impl/data/DirUtil.java