【发布时间】:2013-01-20 13:36:59
【问题描述】:
基本上我有一个用 Python 2.6 编写的 FileExplorer 类。效果很好,我可以浏览驱动器、文件夹等。 但是,当我到达特定文件夹 'C:\Documents and Settings/.*'*,我的脚本所基于的 os.listdir 会引发此错误:
WindowsError:[错误 5] 访问被拒绝:'C:\Documents and Settings/.'
这是为什么呢?是因为这个文件夹是只读的吗?还是 Windows 正在保护的东西而我的脚本无法访问?!
这是有问题的代码(第 3 行):
def listChildDirs(self):
list = []
for item in os.listdir(self.path):
if item!=None and\
os.path.isdir(os.path.join(self.path, item)):
print item
list.append(item)
#endif
#endfor
return list
【问题讨论】:
-
哪个版本的 Windows?在 Vista 及更高版本中,C:\Documents and Settings 是一个联结,而不是一个真正的目录。
-
这是 Windows 7,抱歉忘了说。
标签: python windows file operating-system