def recursive_pattern_delete(root, file_patterns, directory_patterns, dry_run=False):
    """Recursively deletes files matching a list of patterns. Same for directories"""
    for root, dirs, files in os.walk(root):
        for pattern in file_patterns:
            for file_name in fnmatch.filter(files, pattern):
                file_path = os.path.join(root, file_name)
                if dry_run:
                    print_('Removing {}'.format(file_path))
                    continue
                os.remove(file_path)

        for pattern in directory_patterns:
            for found_dir in fnmatch.filter(dirs, pattern):
                if os.path.exists(found_dir):
                    if dry_run:
                        print('Removing directory tree {}'.format(found_dir))
                        continue
                    shutil.rmtree(found_dir)
Recursively deletes files matching a list of patterns. Same for directories