@classmethod<EOL><INDENT>def directory(cls, directory, root=None, extension=None, **kwargs):<DEDENT>
root = os.getcwd() if root is None else root<EOL>suffix = '<STR_LIT>' if extension is None else '<STR_LIT:.>' + extension.rsplit('<STR_LIT:.>')[-<NUM_LIT:1>]<EOL>pattern = directory + os.sep + '<STR_LIT:*>' + suffix<EOL>key = os.path.join(root, directory,'<STR_LIT:*>').rsplit(os.sep)[-<NUM_LIT:2>]<EOL>format_parse = list(string.Formatter().parse(key))<EOL>if not all([el is None for el in zip(*format_parse)[<NUM_LIT:1>]]):<EOL><INDENT>raise Exception('<STR_LIT>')<EOL><DEDENT>return cls(key, pattern, root, **kwargs)<EOL>
Load all the files in a given directory selecting only files
with the given extension if specified. The given kwargs are
passed through to the normal constructor.