How to remove read-only attrib directory with Python in Windows?

前端 未结 5 591
野的像风
野的像风 2020-11-29 08:20

I have a read only directory copied from version controlled directory which is locked. \"enter

5条回答
  •  有刺的猬
    2020-11-29 08:41

    The method that I have used is to do:

    if os.path.exists(target) :
        subprocess.check_call(('attrib -R ' + target + '\\* /S').split())
        shutil.rmtree(target)
    

    Before anyone jumps on me, I know that this is dreadfully un-pythonic, but it is possibly simpler than the more traditional answers given above, and has been reliable.

    I'm not sure what happens regarding read/write attributes on directories. But it hasn't been an issue yet.

提交回复
热议问题