<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def construct(cls, faker, path_to_factories=None):
 """ Create a new factory container. :param faker: A faker generator instance :type faker: faker.Generator :param path_to_factories: The path to factories :type path_to_factories: str :rtype: Factory """

        factory = faker.__class__()

        if path_to_factories is not None and os.path.isdir(path_to_factories):
            for filename in os.listdir(path_to_factories):
                if os.path.isfile(filename):
                    cls._resolve(path_to_factories, filename)

        return factory