code: def _get_file_name(nii_file):
      """Identify the confounds file associated with a functional image.
  
      Parameters
      ----------
      nii_file : str
          Path to the functional image file.
  
      Returns
      -------
      confound_file : str
          Path to the associated confounds file.
      """
      if isinstance(nii_file, list):  # catch gifti
          nii_file = nii_file[0]
  
      base_dir = os.path.dirname(nii_file)
  
      filenames = _generate_confounds_file_candidates(nii_file)
  
      # fmriprep has changed the file suffix between v20.1.1 and v20.2.0 with
      # respect to BEP 012.
      # cf. https://neurostars.org/t/naming-change-confounds-regressors-to-confounds-timeseries/17637 # noqa
      # Check file with new naming scheme exists or replace,
      # for backward compatibility.
      suffixes = ["_timeseries.tsv", "_regressors.tsv"]
  
      confound_file_candidates = []
      for suffix in suffixes:
          confound_file_candidates += [f + suffix for f in filenames]
  
      # Sort the potential filenames by decreasing length,
      # so earlier entries reflect more retained entities.
      # https://www.geeksforgeeks.org/python-sort-list-of-lists-by-the-size-of-sublists/
      confound_file_candidates = sorted(
          confound_file_candidates, key=len
      )[::-1]
      confound_file_candidates = [
          os.path.join(base_dir, crc)
          for crc in confound_file_candidates
      ]
      found_files = [
          cr for cr in confound_file_candidates if os.path.isfile(cr)
      ]
  
      if not found_files:
          raise ValueError(
              "Could not find associated confound file. "
              "The functional derivatives should exist under the same parent "
              "directory."
          )
      elif len(found_files) != 1:
          found_str = "\n\t".join(found_files)
          raise ValueError(
              f"Found more than one confound file:\n\t{found_str}"
          )
      else:
          return found_files[0]
  
imports: import itertools
  import json
  import os
  import re
  import numpy
  import pandas
  from sklearn.preprocessing import scale
  from nilearn._utils.fmriprep_confounds import flag_single_gifti, is_camel_case
  from nilearn.interfaces.bids import parse_bids_filename
  from .load_confounds_scrub import extract_outlier_regressors
label_desc: Use image node_id 6 for calling a global function with example usage: _get_file_name(nii_file) and returns: found_files