def get_files(path, exclude=list(), depth=-1, followlinks=False, extension=None, **extras):
    """
    Retrieves files from the given path with configurable behavior.

    :param path: Path to search for files
    :param depth: Limits the depth of the search. -1 = Unlimited
    :param followLinks: Enables the search to follow links.
    :param exclude: Excludes subdirectories with names in this list.
    :param extension: Restricts results to files matching the given extension."
    """
    # os.walk and os.path.isfile fail silently. We want to be loud!
    if not os.path.exists(path):
        raise ValueError("Location `{0}` does not exist".format(path))

    # If an extension is supplied, use it to do a type check
    if extension:
        type_check = lambda path: os.path.splitext(path)[1][1:].lower() == extension.lower()
    else:
        type_check = lambda n: True

    # os.walk can't handle file paths, only directories
    if os.path.isfile(path):
        if type_check(path):
            yield path
        else:
            pass  # return and halt the generator

    else:
        for root, directories, filenames in os.walk(path, followlinks=followlinks):
            # Exclude the indicated directories by removing them from `directories`
            for directory in list(directories):
                if directory in exclude or depth == 0:
                    directories.remove(directory)

            # Extend our return value only with the allowed file type and regex
            for filename in filter(type_check, filenames):
                yield os.path.join(root, filename)

            depth -= 1
dataset/ETHPy150Open GraylinKim/sc2reader/sc2reader/utils.py/get_files/original