I want to know if there is a way to determine if a file in a directory is executable or not using the new C++17/20 #include <filesystem>
. I do not want to use Boost. I know how this can be done with stat
, st_mode
and S_IXUSR
but I haven't found a way to do it with pure C++17/20.
Asked
Active
Viewed 629 times
1

Nicol Bolas
- 449,505
- 63
- 781
- 982

user482813
- 43
- 5
-
Could [this](https://stackoverflow.com/a/55579815/11024053) help? – faressalem Apr 25 '20 at 21:04
1 Answers
2
Check execution permissions, that is owner_exec
, group_exec
and other_exec
attributes of the corresponding std::experimental::filesystem::permissions
struct. Given a filename, it can be retrieved with
namespace fs = std::experimental::filesystem;
// ...
const auto permissions = fs::status("file.txt").permissions();
Check these according what you know about current user (is the current user owner of file, in file's user group).

michaeldel
- 2,204
- 1
- 13
- 19
-
-
I don't think this is applicable to Windows? Windows doesn't really do the whole "permissions" thing. I could just check myself but I'd have to boot up Windows to do it... Ugh. – Roflcopter4 Feb 18 '22 at 03:52