import re
import pathlib


def get_filenames_by_re(folders, fn_regexp):
    """
    Retrieve all files matching the re.Path
    Args:
        folders: an iterable of input_data_folders
        fn_regexp: a regular expression to identify valid files
    Returns:
        Dict with key=Filename and values=Folders
    """
    fns = []
    re_fn = re.compile(fn_regexp)
    for fol in folders:
        for file in pathlib.Path(fol).rglob('*'):
            if re_fn.match(str(file)):
                fns.append(file)
    return fns