How to detect if a file is executable on Windows?
rasmussen.bryan at gmail.com
Tue Feb 19 09:08:45 EST 2019
Well, I used to know the answer to this question but I haven't done this
kind of thing since 2009, so hopefully what I suggest is not out of date,
so for everything I say here assume I put provisos in like it used to be or
Anyway if the type of a file is executable , for example a file with
extension .xyz, is determined by the registry in windows
read here and google onward
As I recall somewhere in PyWin32
http://timgolden.me.uk/pywin32-docs/contents.html there was a method to
find out if an individual file was an executable.
Hope it helps, because that means I still have some usable knowledge in
On Tue, Feb 19, 2019 at 2:49 PM Stephane Wirtel <stephane at wirtel.be> wrote:
> 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,
> On 02/18, Igor Korot wrote:
> >On Tue, Feb 19, 2019 at 7:26 AM Stephane Wirtel <stephane at wirtel.be>
> >> 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
More information about the Python-list