import re


def build_filter(pattern):
    """Function to return a filter function for scan_directories

    Parameters
    ----------
    pattern : str
        Regex pattern to match

    Returns
    -------
        function : a filter which returns true when a file matching
                   the pattern is present
    """

    def filter(files):

        for f in files:
            if re.match(pattern, f):
                return True

        return False

    return filter