File Permissions

Lenny Self lenny at squiggie.com
Thu Aug 31 15:42:42 EDT 2000


"Fredrik Lundh" <effbot at telia.com> wrote in message
news:Z%wr5.4967$HK.231026 at newsc.telia.net...
> Lenny Self <lenny at squiggie.com> wrote:
> > After looking though the Python Essential Reference and the Python
Library
> > Reference I am still stumped on how to get a file's permissions. I have
been
> > able to get a file's owner and group IDs using the os.stat function but
it
> > doesn't seem to give me the file's permissions.
> >
> > Can someone help me out?  I'd really appreciate it.
>
> the first member of the stat tuple (ST_MODE) contains
> the permissions, as a bitmask.
>
> you can use the functions and macros in the "stat" module
> to decipher them.
>
>     st = os.stat(myfile)
>     mode = st[stat.ST_MODE]
>     if mode & stat.ST_IREAD:
>         print "readable"
>     if mode & stat.ST_IWRITE:
>         print "writable"
>     if mode & stat.ST_IEXEC:
>         print "executable"
>
> (etc)
>
> </F>
>
> <!-- daily news from the python universe:
> http://www.pythonware.com/daily/index.htm
> -->
>

Thanks for your help but I only seem to be able to check whether or not the
user running the script has "rwx" permissions.  I am looking to find the
permissions for owner/group/other, preferably in numeric mode. Is there a
function that allows this that I just haven't found? Are you aware of any
add-on modules that might do this... You plug in a file and it spits out the
file's permissions.

I really do appreciate your help.

    -- Lenny





More information about the Python-list mailing list