Search for files in all subfolders of specified directory, return
    filepaths of all matching instances.

    :param targetfilename: filename to search for, only the string before the
        last "." is used for filename matching. Ignored if a selector function
        is specified.
    :param directory: search directory, including all subdirectories
    :param targetFileExtension: string after the last "." in the filename, has
        to be identical if specified. "." in targetFileExtension are ignored,
        thus ".txt" is treated equal to "txt".
    :param selector: a function which is called with the value of targetfilename
        and has to return True (include value) or False (discard value). If no
        selector is specified, equality to targetfilename is used.

    :returns: list of matching file paths (str)

def matchingFilePaths(targetfilename, directory, targetFileExtension=None,
                      selector=None):
    """Search for files in all subfolders of specified directory, return
    filepaths of all matching instances.

    :param targetfilename: filename to search for, only the string before the
        last "." is used for filename matching. Ignored if a selector function
        is specified.
    :param directory: search directory, including all subdirectories
    :param targetFileExtension: string after the last "." in the filename, has
        to be identical if specified. "." in targetFileExtension are ignored,
        thus ".txt" is treated equal to "txt".
    :param selector: a function which is called with the value of targetfilename
        and has to return True (include value) or False (discard value). If no
        selector is specified, equality to targetfilename is used.

    :returns: list of matching file paths (str)
    """
    targetFilePaths = list()

    targetfilename = os.path.splitext(targetfilename)[0]
    targetFileExtension = targetFileExtension.replace('.', '')
    matchExtensions = False if targetFileExtension is None else True
    if selector is None:
        selector = functools.partial(operator.eq, targetfilename)

    for dirpath, dirnames, filenames in os.walk(directory):
        for filename in filenames:
            filenameNoextension = os.path.splitext(filename)[0]

            if selector(filenameNoextension):
                if matchExtensions:
                    if not filename.endswith('.' + targetFileExtension):
                        continue
                targetFilePaths.append(joinpath(dirpath, filename))
    return targetFilePaths