r""" Creates a hash file for each file in a path

    CommandLine:
        python -m utool.util_hash --test-write_hash_file_for_path

    Example:
        >>> # DISABLE_DOCTEST
        >>> import os
        >>> import utool as ut
        >>> from utool.util_hash import *  # NOQA
        >>> fpath = ut.grab_test_imgpath('patsy.jpg')
        >>> path, _ = os.path.split(fpath)
        >>> hash_fpath_list = write_hash_file_for_path(path)
        >>> for hash_fpath in hash_fpath_list:
        >>>     assert os.path.exists(hash_fpath)
        >>>     ut.delete(hash_fpath)

def write_hash_file_for_path(path, recompute=False):
    r""" Creates a hash file for each file in a path

    CommandLine:
        python -m utool.util_hash --test-write_hash_file_for_path

    Example:
        >>> # DISABLE_DOCTEST
        >>> import os
        >>> import utool as ut
        >>> from utool.util_hash import *  # NOQA
        >>> fpath = ut.grab_test_imgpath('patsy.jpg')
        >>> path, _ = os.path.split(fpath)
        >>> hash_fpath_list = write_hash_file_for_path(path)
        >>> for hash_fpath in hash_fpath_list:
        >>>     assert os.path.exists(hash_fpath)
        >>>     ut.delete(hash_fpath)
    """
    hash_fpath_list = []
    for root, dname_list, fname_list in os.walk(path):
        for fname in sorted(fname_list):
            # fpath = os.path.join(path, fname)
            fpath = os.path.join(root, fname)
            hash_fpath = write_hash_file(fpath, recompute=recompute)
            if hash_fpath is not None:
                hash_fpath_list.append(hash_fpath)
    return hash_fpath_list