2012-10-20 10 views

回答

3

我想分享一個適合我的簡單方法。使用rmtree的時候,把它添加到onerror參數然後

import stat # needed for file stat 
def remShut(*args): 
    func, path, _ = args # onerror returns a tuple containing function, path and  exception info 
    os.chmod(path, stat.S_IWRITE) 
    os.remove(path) 

import shutil 
shutil.rmtree(desiredpath, onerror = remShut) 

我只是做了更改文件的寫權限模式,然後用os.remove將其刪除功能

希望它可以幫助我遇到同樣麻煩的人。

相關問題