code: def get_filenames(dirname, full_path=False, match_regex=None, extension=None):
      
      if not os.path.exists(dirname):
          raise OSError('directory "{}" does not exist'.format(dirname))
      match_regex = re.compile(match_regex) if match_regex else None
      for filename in sorted(os.listdir(dirname)):
          if extension and not os.path.splitext(filename)[-1] == extension:
              continue
          if match_regex and not match_regex.search(filename):
              continue
          if full_path is True:
              yield os.path.join(dirname, filename)
          else:
              yield filename
docs: Get all filenames under ``dirname`` that match ``match_regex`` or have file
      extension equal to ``extension``, optionally prepending the full path.
  
      Args:
          dirname (str): /path/to/dir on disk where files to read are saved
          full_path (bool): if False, return filenames without path; if True,
              return filenames with path, as ``os.path.join(dirname, fname)``
          match_regex (str): include files whose names match this regex pattern
          extension (str): if files only of a certain type are wanted,
              specify the file extension (e.g. ".txt")
  
      Yields:
          str: next matching filename