1

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.

Nicol Bolas
  • 449,505
  • 63
  • 781
  • 982
user482813
  • 43
  • 5

1 Answers1

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
  • Thank you. I was searching all over, can't believe I missed this. – user482813 Apr 25 '20 at 21:15
  • 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