【发布时间】:2013-11-01 14:33:18
【问题描述】:
尝试使用 python 脚本自动删除文件,我得到:
Traceback (most recent call last):
Python script "5", line 8, in <module>
shutil.rmtree(os.path.join(root, d))
File "shutil.pyc", line 221, in rmtree
File "shutil.pyc", line 219, in rmtree
WindowsError: [Error 5] Access is denied: 'C:\\zDump\\TVzip\\Elem.avi'
使用这个
import os
import shutil
for root, dirs, files in os.walk(eg.globals.tvzip):
for f in files:
os.remove(os.path.join(root, f))
for d in dirs:
shutil.rmtree(os.path.join(root, d))
for root, dirs, files in os.walk(eg.globals.tvproc):
for f in files:
os.remove(os.path.join(root, f))
for d in dirs:
shutil.rmtree(os.path.join(root, d))
所有都以管理员身份运行,有什么帮助吗?
【问题讨论】:
-
检查以确保文件不是
read only。也有可能该文件还有一个打开的文件句柄。 -
尝试
os.chmod,然后再次尝试删除它 -
非常感谢,文件夹的权限发生了一些变化。谢谢!!!
标签: python