REPORT_PATH='/Users/lucky/Desktop/Auto/Daas_Interface/python_Interface_new/DaasApiTesting/Report' #路径 def delete_file(path=REPORT_PATH): ''' :param REPORT_PATH: 要删除文件的上层目录地址 :explain:删除测试报告/Report 目录下的所有文件 ''' ls = os.listdir(path) # os.listdir:返回指定的文件夹包含的文件或文件夹的名字的列表 for i in ls: c_path = os.path.join(path, i) # join:将路径和文件结合成一个路径 if os.path.isdir(c_path): # isdir:是否为一个目录 delete_file(c_path) else: os.remove(c_path) delete_file()
注:使用时仅需要将 REPORT_PATH 的路径改为自己的路径即可