code: def rgetcwd(error=True):
      """
      Robust replacement for getcwd when folders get removed
      If error==True, this is just an alias for os.getcwd()
      """
      if error:
          return os.getcwd()
  
      try:
          cwd = os.getcwd()
      except OSError as exc:
          # Changing back to cwd is probably not necessary
          # but this makes sure there's somewhere to change to.
          cwd = os.getenv("PWD")
          if cwd is None:
              raise OSError(
                  (
                      exc.errno,
                      "Current directory does not exist anymore, "
                      "and nipype was not able to guess it from the environment",
                  )
              )
          warn(
              'Current folder does not exist, replacing with "%s" instead.'
              % cwd
          )
      return cwd
  
file_path: nipype/nipype/utils/misc.py
imports: import os
  import sys
  import re
  from collections.abc import Iterator
  from warnings import warn
  from looseversion import LooseVersion
  import numpy
  import textwrap
label_desc: Use image node_id 12 for calling a global function with example usage: rgetcwd(error) and returns: cwd, os