code: def get_latest_subfolder(parent_folder, create_new=False):
      """
      Automatically determine the latest folder n if there are n folders
      in `parent_folder`, and create the (n+1)th folder if required.
      This is used in accessing/creating log folders of multiple runs.
  
      :param parent_folder:
      :param create_new:
      :return:
      """
      parent_folder = touch_folder(parent_folder)
      try:
          log_sub_dirs = os.listdir(parent_folder)
      except OSError:
          tf.logging.fatal("not a directory {}".format(parent_folder))
          raise OSError
      log_sub_dirs = [
          name for name in log_sub_dirs if re.findall("^[0-9]+$", name)
      ]
      if log_sub_dirs and create_new:
          latest_id = max([int(name) for name in log_sub_dirs])
          log_sub_dir = "{}".format(latest_id + 1)
      elif log_sub_dirs and not create_new:
          latest_valid_id = max(
              [
                  int(name)
                  for name in log_sub_dirs
                  if os.path.isdir(os.path.join(parent_folder, name))
              ]
          )
          log_sub_dir = "{}".format(latest_valid_id)
      else:
          log_sub_dir = "{}".format(0)
      return os.path.join(parent_folder, log_sub_dir)
  
imports: from __future__ import absolute_import, print_function, unicode_literals
  import errno
  import importlib
  import logging
  import os
  import re
  import sys
  import warnings
  import nibabel
  import numpy
  import pandas
  import scipy.ndimage
  import tensorflow
  from tensorflow.core.framework import summary_pb2
  from niftynet.io.image_loader import load_image_obj
  from niftynet.utilities.niftynet_global_config import NiftyNetGlobalConfig
  from niftynet.utilities.util_import import require_module
label_desc: Use image node_id 22 for calling a global function with example usage: get_latest_subfolder(parent_folder, create_new) and returns: os