python - 需要检查是否存在多个目录
问题描述
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'
解决方案
在shutil.rmtree(dir, ignore_errors=true)
你使用dir
的是 python 内置函数,也许你想做shutil.rmtree(path, ignore_errors=true)
推荐阅读
- javascript - DateTimeFormat 是否考虑夏令时?
- elixir - 如何使用 Mix CLI 安装早期版本的 Phoenix?
- visual-studio-code - 无法阻止保存时换行
- flutter - 在 `.symlinks/plugins/cloud_firestore/ios` 中找不到 `cloud_firestore` 的 podspec
- cassandra - cassandra 可能的节点丢失
- salesforce - Docusign Rest API:无法将 docusign 与 salesforce 记录相关联
- mysql - MYSQL如何比较字符串
- android - twitchapi 的授权令牌
- java - 我如何获得父父工具栏名称
- mysql - 在 AWS Lambda 中获取“完成请求之前退出进程”