How to find if a file is executable

Curly Joe woooee at yahoo.com
Fri Jun 13 22:48:05 EDT 2003


To whomever posted the question, this is late but I
forgot that I had this little bit of code.  You have
to use the bitwise & operator, not "and".  This also
does not work:
if mode:
    if stat.S_ISLNK(st[stat.ST_MODE]) :

<CODE>
import os
import sys
import stat
import string

##----  Test files permissions
def file_permissions( myfile ) :
    st = os.stat(myfile)
    ##--- st = tuple, in format 
    ##    (mode,ino,dev,nlink,uid,gid,size,
    ##     atime,mtime,ctime)
    mode = st[0]
         
    if mode :
        print "st_mode = ", mode
    if mode & stat.S_ISLNK(st[stat.ST_MODE]) :
        print "is link"
    else :
        print "is NOT link"		
    if mode & stat.S_IREAD :
        print "readable"
    if mode & stat.S_IWRITE :
        print "writable"
    if mode & stat.S_IEXEC:
        print "executable"
</CODE>

If I'm too late, sorry.


__________________________________
Do you Yahoo!?
SBC Yahoo! DSL - Now only $29.95 per month!
http://sbc.yahoo.com





More information about the Python-list mailing list