def _process_directory(files, user_conf, error_protocol):
items = []<EOL>banned = [settings.USER_IMPORT_LOG, settings.USER_ERROR_LOG]<EOL>files = [x for x in files if not os.path.basename(x) in banned]<EOL>if len(files) == <NUM_LIT:2> and conf_merger(user_conf, "<STR_LIT>"):<EOL><INDENT>logger.debug("<STR_LIT>")<EOL>items.extend(_process_pair(files[<NUM_LIT:0>], files[<NUM_LIT:1>], error_protocol))<EOL>files = []<EOL><DEDENT>while files:<EOL><INDENT>same_names = []<EOL>fn = files.pop()<EOL>logger.debug("<STR_LIT>" % fn)<EOL>if conf_merger(user_conf, "<STR_LIT>"):<EOL><INDENT>same_names = _same_named(fn, files)  <EOL>indexes = [i_fn[<NUM_LIT:0>] for i_fn in same_names]  <EOL>same_names = [i_fn1[<NUM_LIT:1>] for i_fn1 in same_names]  <EOL>for i in sorted(indexes, reverse=True):<EOL><INDENT>del files[i]<EOL><DEDENT><DEDENT>SDP = conf_merger(user_conf, "<STR_LIT>")<EOL>if len(same_names) == <NUM_LIT:1> and SDP:<EOL><INDENT>logger.debug(<EOL>"<STR_LIT>" % (fn, same_names[<NUM_LIT:0>])<EOL>)<EOL>items.extend(_process_pair(fn, same_names[<NUM_LIT:0>], error_protocol))<EOL><DEDENT>elif not same_names:  <EOL><INDENT>logger.debug("<STR_LIT>" % fn)<EOL>if _is_meta(fn):<EOL><INDENT>items.append(_safe_read_meta_file(fn, error_protocol))<EOL><DEDENT>else:<EOL><INDENT>items.append(EbookFile(fn))<EOL><DEDENT><DEDENT>else:  <EOL><INDENT>logger.error(<EOL>"<STR_LIT>" % "<STR_LIT:U+002CU+0020>".join(same_names)<EOL>)<EOL>error_protocol.append(<EOL>"<STR_LIT>" +<EOL>"<STR_LIT>".join(same_names) + "<STR_LIT>"<EOL>)<EOL><DEDENT><DEDENT>return [x for x in items if x]<EOL>
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]