private TreeWalkResult treeWalkRecursive(final Folder root, final boolean ordered, final Func1<ImmutablePair<ContentStorage.FileInformation, Boolean>, TreeWalkResult> callback) {

        final List<ContentStorage.FileInformation> files = pls.list(root);
        if (ordered) {
            Collections.sort(files, Comparator.comparing(o -> o.name));
        }
        boolean continueWalk = true;
        for (ContentStorage.FileInformation fi : files) {
            TreeWalkResult twr = callback.call(new ImmutablePair<>(fi, true));
            if (twr == null || twr == TreeWalkResult.STOP) {
                return TreeWalkResult.STOP;
            }
            continueWalk &= twr == TreeWalkResult.CONTINUE;

            if (fi.isDirectory) {
                if (continueWalk) {
                    twr = treeWalkRecursive(fi.dirLocation, ordered, callback);
                    if (twr == TreeWalkResult.STOP) {
                        return TreeWalkResult.STOP;
                    }
                    continueWalk &= twr == TreeWalkResult.CONTINUE;
                }

                twr = callback.call(new ImmutablePair<>(fi, false));
                if (twr == null || twr == TreeWalkResult.STOP) {
                    return TreeWalkResult.STOP;
                }
                continueWalk &= twr == TreeWalkResult.CONTINUE;
            }
        }
        return continueWalk ? TreeWalkResult.CONTINUE : TreeWalkResult.STOP_AFTER_FOLDER;
    }
Returns a pair of longs where left one is free space in bytes and right one is number of files
main/src/main/java/cgeo/geocaching/storage/FolderUtils.java