简体   繁体   中英

How to check if path leads to executable file?

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?

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

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM