Reputation: 53
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.
Upvotes: 1
Views: 1004
Reputation: 2385
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).
Upvotes: 2