Deleting directory in Python

后端 未结 6 616
既然无缘
既然无缘 2020-12-01 12:08

shutil.rmtree will not delete read-only files on Windows. Is there a python equivalent of \"rm -rf\" ? Why oh why is this such a pain?

6条回答
  •  执笔经年
    2020-12-01 12:16

    Another way is to define rmtree on Windows as

    rmtree = lambda path: subprocess.check_call(['cmd', '/c', 'rd', '/s', '/q', path])
    

提交回复
热议问题