我们需要检查当前Windows帐户是否对Windows文件夹具有listdir/[List Folder Contents][1]权限。目前我们正在使用os.access(path, os.R_OK)。但是,据我所知,windows用户可以在没有List folder Conents权限的情况下读取文件夹。在
我的测试:
创建一个fodler,配置Security,拒绝List folder / read data权限。在
当我在windows文件资源管理器中访问它时,You don't currently have permission to access this folder——这就是我所期望的。但是,当我在python中测试时:>>> p = r'c:\tmp\p'
>>> os.stat(p)
nt.stat_result(st_mode=16895, st_ino=0L, st_dev=0L, st_nlink=0, st_uid=0, st_gid=0, st_size=0L, st_a
time=1463736204L, st_mtime=1463736204L, st_ctime=1463736135L)
>>> os.access(p, os.R_OK)
True
>>> os.listdir(p)
Traceback (most recent call last):
File "", line 1, in
WindowsError: [Error 5] Access is denied: 'c:\\tmp\\p/*.*'
在操作系统访问=>;正确;操作系统列表=>;异常
问题
我不认为os.access()是测试List Folder Conents权限的合适函数,Python中还有其他函数/lib可以检查listdir(List Folder Contents)权限吗?在
请理解It's easier to ask for forgiveness than for permission,但我仍然想找到一种正确的方法来验证listdir权限。谢谢!在