How to find if a file is executable

Curly Joe woooee at
Sat Jun 14 04:48:05 CEST 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]) :

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"

If I'm too late, sorry.

Do you Yahoo!?
SBC Yahoo! DSL - Now only $29.95 per month!

More information about the Python-list mailing list