code: def match_and_write_filenames_to_csv(list_constraints, csv_file):
      """
      Combine all elements of file searching until finally writing the names
      :param list_constraints: list of constraints (defined by list of paths to
      search, list of elements the filename should contain and of those that
      are forbidden
      :param csv_file: file on which to write the final list of files.
      :return:
      """
      name_tot = []
      list_tot = []
      if list_constraints is None or len(list_constraints) == 0:
          return
      for c in list_constraints:
          (
              list_files,
              name_list,
          ) = KeywordsMatching.matching_subjects_and_filenames(c)
          name_list = remove_duplicated_names(name_list)
          name_tot.append(name_list)
          list_tot.append(list_files)
      list_combined = join_subject_id_and_filename_list(
          name_tot, list_tot
      )
      list_combined = filter(
          lambda names: "" not in names, list_combined
      )
      list_combined = list(list_combined)
      if not list_combined:
          raise IOError("Nothing to write to {}".format(csv_file))
      touch_folder(os.path.dirname(csv_file))
      write_csv(csv_file, list_combined)
  
      return list_combined
  
file_path: NiftyNet/niftynet/utilities/util_csv.py
imports: from __future__ import absolute_import, print_function, division
  import csv
  import os
  import sys
  from difflib import SequenceMatcher
  import numpy
  from niftynet.io.misc_io import touch_folder
  from niftynet.utilities.filename_matching import KeywordsMatching
label_desc: Use image node_id 7 for calling a global function with example usage: match_and_write_filenames_to_csv(list_constraints, csv_file) and returns: list_combined