纵想开怀 发表于 2014-09-26 14:11

求助:如何用python查看文件夹的权限

求助:如何用python查看文件夹的权限?非常感谢

whitelotus19 发表于 2014-10-22 22:35

#!/usr/bin/env python
# -*- coding: utf-8 -*-

import os

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

tsdname=r'/home/lotus/temp/ts'
if os.access(tsdname,os.R_OK):
    print 'directory %s :readability ok' % tsdname
if os.access(tsdname,os.W_OK):
    print 'directory %s :writability ok' % tsdname
linux上的执行样子:$ ls -lh
total 4.0K
-rwxrw-r--. 1 lotus lotus 446 Oct 22 22:32 test.py
dr-xrwxr-x. 2 lotus lotus   6 Oct 22 22:32 ts
$ ./test.py
file /home/lotus/temp/test.py :readability ok
file /home/lotus/temp/test.py :writability ok
directory /home/lotus/temp/ts :readability ok
$ 帮助文档有说明啊

纵想开怀 发表于 2014-11-06 10:23

非常感谢,学习了回复 2# whitelotus19


   

whitelotus19 发表于 2014-11-06 11:11

纵想开怀 发表于 2014-11-06 10:23 static/image/common/back.gif
非常感谢,学习了回复 2# whitelotus19

:emn35:
页: [1]
查看完整版本: 求助:如何用python查看文件夹的权限