code: def convert_files(root_dir, sub_dir, writer, recursive=False):
      """Converts files.
  
      Args:
        root_dir: A string specifying a root directory.
        sub_dir: A string specifying a path to a directory under `root_dir` in which
            to convert contents.
        writer: A TFRecord writer
        recursive: A boolean specifying whether or not recursively convert files
            contained in subdirectories of the specified directory.
  
      Returns:
        A map from the resulting Futures to the file paths being converted.
      """
      dir_to_convert = os.path.join(root_dir, sub_dir)
      tf.logging.info("Converting files in '%s'.", dir_to_convert)
      files_in_dir = tf.gfile.ListDirectory(
          os.path.join(dir_to_convert)
      )
      recurse_sub_dirs = []
      written_count = 0
      for file_in_dir in files_in_dir:
          tf.logging.log_every_n(
              tf.logging.INFO,
              "%d files converted.",
              1000,
              written_count,
          )
          full_file_path = os.path.join(dir_to_convert, file_in_dir)
          if full_file_path.lower().endswith(
              ".mid"
          ) or full_file_path.lower().endswith(".midi"):
              try:
                  sequence = convert_midi(
                      root_dir, sub_dir, full_file_path
                  )
              except Exception as exc:  # pylint: disable=broad-except
                  tf.logging.fatal(
                      "%r generated an exception: %s",
                      full_file_path,
                      exc,
                  )
                  continue
              if sequence:
                  writer.write(sequence.SerializeToString())
          elif full_file_path.lower().endswith(
              ".xml"
          ) or full_file_path.lower().endswith(".mxl"):
              try:
                  sequence = convert_musicxml(
                      root_dir, sub_dir, full_file_path
                  )
              except Exception as exc:  # pylint: disable=broad-except
                  tf.logging.fatal(
                      "%r generated an exception: %s",
                      full_file_path,
                      exc,
                  )
                  continue
              if sequence:
                  writer.write(sequence.SerializeToString())
          elif full_file_path.lower().endswith(".abc"):
              try:
                  sequences = convert_abc(
                      root_dir, sub_dir, full_file_path
                  )
              except Exception as exc:  # pylint: disable=broad-except
                  tf.logging.fatal(
                      "%r generated an exception: %s",
                      full_file_path,
                      exc,
                  )
                  continue
              if sequences:
                  for sequence in sequences:
                      writer.write(sequence.SerializeToString())
          else:
              if recursive and tf.gfile.IsDirectory(full_file_path):
                  recurse_sub_dirs.append(
                      os.path.join(sub_dir, file_in_dir)
                  )
              else:
                  tf.logging.warning(
                      "Unable to find a converter for file %s",
                      full_file_path,
                  )
  
      for recurse_sub_dir in recurse_sub_dirs:
          convert_files(root_dir, recurse_sub_dir, writer, recursive)
  
file_path: magenta/magenta/scripts/convert_dir_to_note_sequences.py
imports: import hashlib
  import os
  from note_seq import abc_parser
  from note_seq import midi_io
  from note_seq import musicxml_reader
  import tensorflow.compat.v1
label_desc: Use image node_id 2 for calling a global function with example usage: convert_files(root_dir, sub_dir, writer, recursive) without return types