Need Simple Way To Determine If File Is Executable

Tim Roberts timr at probo.com
Thu Dec 21 23:44:38 EST 2006


Sebastian 'lunar' Wiesner <basti.wiesner at gmx.net> wrote:
>
>Fredrik Lundh <fredrik at pythonware.com> schrieb
>
>> Sebastian 'lunar' Wiesner wrote:
>> 
>>>> you're confusing the shell's "is this file executable" check with
>>>> the loader's "can I execute this file" check:
>...
>Well, that doesn't tell us anything about, whether a file executable or
>not.
>But anyway: you admit, that the local file "ls" is __not__ actually
>executable, although it has the x-bit set?

Sebastian, you really have missed the point of this thread.  The original
question was "how can I find out if a file is executable".  The answer
involved calling stat.  On a Linux system, using stat, the definition of
"executable" is "has the x mode bit set".  On a Windows system, using stat,
the definition is "has an extension that is in PATHEXT".  Nothing more,
nothing less.  In both cases, the contents of the file are irrelevant.

Now, when you, as a human being, try answer the question "is this file
executable", you would use more sophisticated criteria that looked at the
first bytes of the file, but that's not the question here.
-- 
Tim Roberts, timr at probo.com
Providenza & Boekelheide, Inc.



More information about the Python-list mailing list