首页 > 解决方案 > 需要检查是否存在多个目录

问题描述

def check_and_remove(pathslist):
    for path in pathslist:
        if os.path.exists(path) and os.path.isdir(path):
        shutil.rmtree(path, ignore_errors=true)
        print("Deleted")
    else:
        print(path, " directory not found")

dirs_to_delete = [
'C:\Directory1',
'C:\Directory2',
'C:\Directory3'
]

check_and_remove()

将建议的 shutil.rmtree(dir, ignore_errors=true) 更改为 shutil.rmtree(path, ignore_errors=true)

现在收到此错误-

回溯(最后一次调用):文件“C:\Users\Temp\PycharmProjects\crm\CRMReinstall.py”,第 53 行,在 check_and_remove() 类型错误:check_and_remove() 缺少 1 个必需的位置参数:'pathslist'

标签: pythonpython-3.x

解决方案


shutil.rmtree(dir, ignore_errors=true)你使用dir的是 python 内置函数,也许你想做shutil.rmtree(path, ignore_errors=true)


推荐阅读