How to check if path leads to executable file?

六月ゝ 毕业季﹏ 提交于 2019-12-23 09:37:31

问题


I try to create some kind of file browser. I want to know if file under path is executable in a cross-platform way.

How to do such thing with boost::filesystem?


回答1:


Boost doesn't have stuff about permissions, because POSIX permissions are not "crossplatform".

Use the platform-specific APIs at your disposal as required. Sorry!




回答2:


You can try QT. It is cross-platform. You do not have to care about the operating system differences while dealing with files. What you mean by "executable" is somehow unclear though. If you are talking about file permissions, OT can give this kind of information (Just look at QFile class documentation). If you want to learn whether you can actually run it or not, you have to have some kind of file extension convention. For example, .exe in Windows. I do not know, may be there is a way to look at the initial bits of the file and learn whether it is a binary or not, but I think you will not be able to find a library call for that. You have to implement some platform specific routines for this. If I am not mistaken, file browsers mostly look at the extension of the file to find out the type. For example, if you change the file extension of a pdf to exe than windows explorer sees this file as an executable. Clearly after the file type assumption, it can try to learn some other things about the file, such as icon of the executable. But initially it only looks at the extension. Otherwise, it would be very slow to browse directories containing large numbers of files.

I hope, I gave some relevant information here



来源:https://stackoverflow.com/questions/5719438/how-to-check-if-path-leads-to-executable-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!