Chinaunix

标题: 求助:如何用python查看文件夹的权限 [打印本页]

作者: 纵想开怀    时间: 2014-09-26 14:11
标题: 求助:如何用python查看文件夹的权限
求助:如何用python查看文件夹的权限?非常感谢
作者: whitelotus19    时间: 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]$
复制代码
帮助文档有说明啊
作者: 纵想开怀    时间: 2014-11-06 10:23
非常感谢,学习了回复 2# whitelotus19


   
作者: whitelotus19    时间: 2014-11-06 11:11
纵想开怀 发表于 2014-11-06 10:23
非常感谢,学习了回复 2# whitelotus19







欢迎光临 Chinaunix (http://bbs.chinaunix.net/) Powered by Discuz! X3.2