<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def to_files(self, resource, directory):
 """ Dumps the given resource and all resources linked to it into a set of representation files in the given directory. """

        collections = self.__collect(resource)
        for (mb_cls, coll) in iteritems_(collections):
            fn = get_write_collection_path(mb_cls,
                                           self.__content_type,
                                           directory=directory)
            with open_text(os.path.join(directory, fn)) as strm:
                dump_resource(coll, strm, content_type=self.__content_type)