python os判断文件夹是否存在,若存在删除,重新创建文件夹

os判断文件夹是否存在,若存在删除,重新创建文件夹

 filePath = r'C:\Users\Administrator\Desktop\step2'  # 文件路径
    if os.path.exists(filePath):
        for fileList in os.walk(filePath):
            for name in fileList[2]:
                os.chmod(os.path.join(fileList[0], name), stat.S_IWRITE)
                os.remove(os.path.join(fileList[0], name))
        shutil.rmtree(filePath)

    os.mkdir(filePath)

你可能感兴趣的:(数据处理)