免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2136 | 回复: 3
打印 上一主题 下一主题

求助:如何用python查看文件夹的权限 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2014-09-26 14:11 |只看该作者 |倒序浏览
求助:如何用python查看文件夹的权限?非常感谢

论坛徽章:
0
2 [报告]
发表于 2014-10-22 22:35 |只看该作者
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-

  3. import os

  4. tsfname=r'/home/lotus/temp/test.py'
  5. if os.access(tsfname,os.R_OK):
  6.     print 'file %s :readability ok' % tsfname
  7. if os.access(tsfname,os.W_OK):
  8.     print 'file %s :writability ok' % tsfname

  9. tsdname=r'/home/lotus/temp/ts'
  10. if os.access(tsdname,os.R_OK):
  11.     print 'directory %s :readability ok' % tsdname
  12. if os.access(tsdname,os.W_OK):
  13.     print 'directory %s :writability ok' % tsdname
复制代码
linux上的执行样子:
  1. [lotus@rhel7pc1 temp]$ ls -lh
  2. total 4.0K
  3. -rwxrw-r--. 1 lotus lotus 446 Oct 22 22:32 test.py
  4. dr-xrwxr-x. 2 lotus lotus   6 Oct 22 22:32 ts
  5. [lotus@rhel7pc1 temp]$ ./test.py
  6. file /home/lotus/temp/test.py :readability ok
  7. file /home/lotus/temp/test.py :writability ok
  8. directory /home/lotus/temp/ts :readability ok
  9. [lotus@rhel7pc1 temp]$
复制代码
帮助文档有说明啊

论坛徽章:
0
3 [报告]
发表于 2014-11-06 10:23 |只看该作者
非常感谢,学习了回复 2# whitelotus19


   

论坛徽章:
0
4 [报告]
发表于 2014-11-06 11:11 |只看该作者
纵想开怀 发表于 2014-11-06 10:23
非常感谢,学习了回复 2# whitelotus19


您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP