osdir.com


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

How to detect if a file is executable on Windows?


And based on a determinist solution?

Yes, you can check the extension but sometimes I prefer to be sure.

For example, the API of Win32 has the GetTypeBinaryW function, this one
could be used but I need to create a mapping, with CPython api, ctypes
or CFFI.

I could also use the 2 first bytes of a file and determine if the file
is a binary because on Windows, the executable files start with b'MZ'.

But I wanted an elegant and minimalist solution.

Thank you for your proposal.

Have a nice day,

St?phane

On 02/18, Igor Korot wrote:
>Hi,
>
>On Tue, Feb 19, 2019 at 7:26 AM Stephane Wirtel <stephane at wirtel.be> wrote:
>>
>> Hi all,
>>
>> on Linux/Unix/BSD, we can detect if a file is an executable with
>> os.access(path, os.X_OK) but this is not the case on Windows.
>>
>> Do you have an idea?
>
>Check file extension?
>
>Thank you.
>
>>
>> Have a nice day,
>>
>> St?phane
>>
>> --
>> St?phane Wirtel - https://wirtel.be - @matrixise
>> --
>> https://mail.python.org/mailman/listinfo/python-list

-- 
St?phane Wirtel - https://wirtel.be - @matrixise