shutil.rmtree可以采用一个错误处理函数,该函数在删除文件时会遇到问题。您可以使用它来强制删除有问题的文件。
灵感来自http://mail.python.org/pipermail/tutor/2006-June/047551.html和http://techarttiki.blogspot.com/2008/08/read-
only-windows-files-with-python。
html:
import osimport statimport shutildef remove_readonly(func, path, excinfo): os.chmod(path, stat.S_IWRITE) func(path)shutil.rmtree(top, onerror=remove_readonly)
(我尚未测试该代码段,但足以让您入门)



