code: def _check_fname(
      fname,
      overwrite=False,
      must_exist=False,
      name="File",
      need_dir=False,
      *,
      verbose=None,
  ):
      """Check for file existence, and return its absolute path."""
      _validate_type(fname, "path-like", name)
      fname = Path(fname).expanduser().absolute()
  
      if fname.exists():
          if not overwrite:
              raise FileExistsError(
                  "Destination file exists. Please use option "
                  '"overwrite=True" to force overwriting.'
              )
          elif overwrite != "read":
              logger.info("Overwriting existing file.")
          if must_exist:
              if need_dir:
                  if not fname.is_dir():
                      raise OSError(
                          f"Need a directory for {name} but found a file "
                          f"at {fname}"
                      )
              else:
                  if not fname.is_file():
                      raise OSError(
                          f"Need a file for {name} but found a directory "
                          f"at {fname}"
                      )
              if not os.access(fname, os.R_OK):
                  raise PermissionError(
                      f"{name} does not have read permissions: {fname}"
                  )
      elif must_exist:
          raise FileNotFoundError(f'{name} does not exist: "{fname}"')
  
      return fname
  
imports: import numbers
  import operator
  import os
  import re
  from builtins import input
  from difflib import get_close_matches
  from importlib import import_module
  from pathlib import Path
  import numpy
  from ..defaults import HEAD_SIZE_DEFAULT, _handle_default
  from ..fixes import _compare_version, _median_complex
  from ._logging import _record_warnings, _verbose_safe_false, logger, verbose, warn
label_desc: Use image node_id 12 for calling a global function with example usage: _check_fname(fname, overwrite, must_exist, name, need_dir) and returns: fname