code: def get_dataset_dir(
      dataset_name, data_dir=None, default_paths=None, verbose=1
  ):
      """Create if necessary and return data directory of given dataset.
  
      Parameters
      ----------
      dataset_name : string
          The unique name of the dataset.
      %(data_dir)s
      default_paths : list of string, optional
          Default system paths in which the dataset may already have been
          installed by a third party software. They will be checked first.
      %(verbose)s
  
      Returns
      -------
      data_dir : string
          Path of the given dataset directory.
  
      Notes
      -----
      This function retrieves the datasets directory (or data directory) using
      the following priority :
  
      1. defaults system paths
      2. the keyword argument data_dir
      3. the global environment variable NILEARN_SHARED_DATA
      4. the user environment variable NILEARN_DATA
      5. nilearn_data in the user home folder
  
      """
      paths = []
      # Search possible data-specific system paths
      if default_paths is not None:
          for default_path in default_paths:
              paths.extend(
                  [
                      (d, True)
                      for d in str(default_path).split(os.pathsep)
                  ]
              )
  
      paths.extend(
          [(d, False) for d in get_data_dirs(data_dir=data_dir)]
      )
  
      if verbose > 2:
          print(f"Dataset search paths: {paths}")
  
      # Check if the dataset exists somewhere
      for path, is_pre_dir in paths:
          if not is_pre_dir:
              path = os.path.join(path, dataset_name)
          if os.path.islink(path):
              # Resolve path
              path = readlinkabs(path)
          if os.path.exists(path) and os.path.isdir(path):
              if verbose > 1:
                  print(f"\nDataset found in {path}\n")
              return path
  
      # If not, create a folder in the first writeable directory
      errors = []
      for path, is_pre_dir in paths:
          if not is_pre_dir:
              path = os.path.join(path, dataset_name)
          if not os.path.exists(path):
              try:
                  os.makedirs(path)
                  _add_readme_to_default_data_locations(
                      data_dir=data_dir,
                      verbose=verbose,
                  )
                  if verbose > 0:
                      print(f"\nDataset created in {path}\n")
                  return path
              except Exception as exc:
                  short_error_message = getattr(
                      exc, "strerror", str(exc)
                  )
                  errors.append(f"\n -{path} ({short_error_message})")
  
      raise OSError(
          "Nilearn tried to store the dataset in the following "
          f"directories, but: {''.join(errors)}"
      )
  
imports: import collections.abc
  import contextlib
  import fnmatch
  import hashlib
  import os
  import pickle
  import shutil
  import sys
  import tarfile
  import time
  import urllib
  import warnings
  import zipfile
  from pathlib import Path
  import numpy
  import requests
  from .._utils import fill_doc
  from .utils import get_data_dirs
label_desc: Use image node_id 8 for calling a global function with example usage: get_dataset_dir(dataset_name, data_dir, default_paths, verbose) and returns: path, path