|
|
Home » U++ Library support » U++ Core » FindFile::IsExecutable() [Feature request]
FindFile::IsExecutable() [Feature request] [message #25685] |
Sun, 07 March 2010 21:51  |
|
Hello,
Would it be possible to add IsExecutable() method to FindFile? Implementation is quite simple, for Linux: bool FindFile::IsExecutable() const { return (!IsDirectory()) && ((S_IXUSR|S_IXGRP|S_IXOTH) & GetMode());} And for windows (this could be optimized):bool FindFile::IsExecutable() const { return ToLower(GetName()).EndsWith(".exe"); }
What do you think?
Best regards,
Honza
|
|
|
|
Re: FindFile::IsExecutable() [Feature request] [message #25712 is a reply to message #25698] |
Tue, 09 March 2010 08:17   |
|
luzr wrote on Mon, 08 March 2010 16:55 | What about directory with .exe extension in Windows? 
Mirek
|
Hi Mirek,
You got me Actually I was hoping that someone who actually knows Windows will write better version using win API...
Now, after I gave it a bit more thinking I think the proper way would be reading PATHEXT environment variable and compare it to the extension of files. On Win98 (if you want to support it) fixed list with .exe and .com should be used. What do you think about this? It is slow, but probably not as slow as opening the file and determining the executability from its contents.
Another solution would be omit this method on Windows the same way as some methods are omitted on Linux because the are not well defined (IsArchive,IsCompressed,...).
Best regards,
Honza
|
|
|
|
Re: FindFile::IsExecutable() [Feature request] [message #25719 is a reply to message #25715] |
Tue, 09 March 2010 11:14   |
Mindtraveller
Messages: 917 Registered: August 2007 Location: Russia, Moscow rgn.
|
Experienced Contributor |

|
|
This is hard question because actually you may execute ANY file in Windows. You may rename your .exe into something like *.scr or even *.abcxyz and execute it with CreateProcess() - and it will work. There is no way to restrict using any file as executable.
So, what question you really want to answer on Windows? Is the file executable? Answer is: any file is executable.
Executable from Explorer? Then, the list from PATHEXT is not enough. There are still more executable types which are registered by Windows but not mentioned in any variables (like .scr which is heavily used by viruses).
[Updated on: Tue, 09 March 2010 11:15] Report message to a moderator
|
|
|
|
Re: FindFile::IsExecutable() [Feature request] [message #25726 is a reply to message #25685] |
Tue, 09 March 2010 12:08   |
|
Hi,
Mirek:
Thank you, that is enough for me...
Mindtraveller:
Yes, PATHEXT contains extensions that can be executed from console. In some sense you could even call any file executable, if it has extension associated with some program (as there is no difference visible in some cases, e.g. opening file.py in python.exe). But for practical use, .exe is probably enough...
Koldo:
Checking the magic number is probably the safest (and slowest) method. Also I read somewhere that even "ZM" should work and some executables could even start with "PE".
Anyway, I'm happy now, whatever on top of this is just bonus 
Honza
|
|
|
|
|
Goto Forum:
Current Time: Wed May 14 07:59:18 CEST 2025
Total time taken to generate the page: 0.01593 seconds
|
|
|