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  的路径改为自己的路径即可

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-09-14
  • 2022-12-23
  • 2022-01-06
  • 2022-12-23
猜你喜欢
  • 2021-12-01
  • 2022-01-29
  • 2022-01-10
  • 2021-07-09
  • 2022-12-23
  • 2022-12-23
  • 2021-10-16
相关资源
相似解决方案