import os import shutil script_path = os.path.dirname(os.path.realpath(__file__)) class FileTools: def mkdir(self, dir): real = self.get_ab_path(dir) if not os.path.exists(real): try: os.mkdir(real) return True except: return False def write(self, file, content): try: with open(self.get_ab_path(file), 'w') as f: f.write(content) return True except: return False def write_b(self, file, content): try: print(file) with open(self.get_ab_path(file), 'wb') as f: f.write(content) return True except Exception as e: print(e) return False def rm(self, dir): full=self.get_ab_path(dir) try: shutil.rmtree(path=full) return True except: return False def get_ab_path(self,path): return "%s/%s" % (script_path, path)