def METHOD_NAME(
    dirpath, callback, user=None, status="zip", is_async=False
):
    """Iterate through all files and directories in the given ``dirpath``."""
    total_file_count = 0
    success_count = 0
    errors = []
    # pylint: disable=too-many-nested-blocks
    for directory, _subdirs, subfiles in os.walk(dirpath):
        for filename in subfiles:
            filepath = os.path.join(directory, filename)
            if XFormInstanceFS.is_valid_instance(filepath):
                xfxs = XFormInstanceFS(filepath)
                if is_async and user is not None:
                    callback.apply_async(
                        (user.username, xfxs.path, xfxs.photos, xfxs.osm, status),
                        queue="instances",
                    )
                    success_count += 1
                else:
                    try:
                        count = callback(xfxs)
                    except Http404:
                        pass
                    else:
                        if count:
                            success_count += count
                    del xfxs
                total_file_count += 1
    return (total_file_count, success_count, errors)