<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def _write_file(self, slug, folderpath, html):
 """ Writes a chart's html to a file """

        # check directories
        if not os.path.isdir(folderpath):
            try:
                os.makedirs(folderpath)
                self.info("Creating directory " + folderpath)
            except Exception as e:
                self.err(e)
                return
        # construct file path
        filepath = folderpath + "/" + slug + ".html"
        # write the file
        try:
            filex = open(filepath, "w")
            filex.write(html)
            filex.close()
            if self.notebook is False:
                self.ok("File written to", filepath)
            else:
                html = '<a href="' + filepath + '">' + filepath + '</a>'
                self.html("File written to", html)
        except Exception as e:
            self.err(e)
        return filepath