docs: def _process_directory(files, user_conf, error_protocol):
      """
      Look at items in given directory, try to match them for same names and pair
      them.
  
      If the items can't be paired, add their representation.
  
      Note:
          All successfully processed files are removed.
  
      Returns:
          list: of items. Example: [MetadataFile, DataPair, DataPair, EbookFile]
      """
      items = []
  
      banned = [settings.USER_IMPORT_LOG, settings.USER_ERROR_LOG]
      files = filter(lambda x: not os.path.basename(x) in banned, files)
  
      if len(files) == 2 and conf_merger(user_conf, "SAME_DIR_PAIRING"):
          logger.debug("There are only two files.")
  
          items.extend(_process_pair(files[0], files[1], error_protocol))
          files = []
  
      while files:
          same_names = []
          fn = files.pop()
  
          logger.debug("Processing '%s'." % fn)
  
          # get files with same names (ignore paths and suffixes)
          if conf_merger(user_conf, "SAME_NAME_DIR_PAIRING"):
              same_names = _same_named(fn, files)  # returns (index, name)
              indexes = map(lambda (i, fn): i, same_names)  # get indexes
              same_names = map(lambda (i, fn): fn, same_names)  # get names
  
              # remove `same_names` from `files` (they are processed in this
              # pass)
              for i in sorted(indexes, reverse=True):
                  del files[i]
  
          # has exactly one file pair
          SDP = conf_merger(user_conf, "SAME_NAME_DIR_PAIRING")
          if len(same_names) == 1 and SDP:
              logger.debug(
                  "'%s' can be probably paired with '%s'." % (fn, same_names[0])
              )
              items.extend(_process_pair(fn, same_names[0], error_protocol))
          elif not same_names:  # there is no similar files
              logger.debug("'%s' can't be paired. Adding standalone file." % fn)
              if _is_meta(fn):
                  items.append(_safe_read_meta_file(fn, error_protocol))
              else:
                  items.append(EbookFile(fn))
          else:  # error - there is too many similar files
              logger.error(
                  "Too many files with same name: %s" % ", ".join(same_names)
              )
              error_protocol.append(
                  "Too many files with same name:" +
                  "\n\t".join(same_names) + "\n\n---\n"
              )
  
      return filter(lambda x: x, items)