<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def replace_text_dir(self, directory, to_replace, replacement, file_type=None):
 """ Replaces a string with its replacement in all the files in the directory :param directory: the directory in which the files have to be modified :param to_replace: the string to be replaced in the files :param replacement: the string which replaces 'to_replace' in the files :param file_type: file pattern to match the files in which the string has to be replaced """

        if not file_type:
            file_type = "*.tex"
        for file in glob.iglob(os.path.join(directory, file_type)):
            self.replace_text(file, to_replace, replacement)