[英]C++17/20 - Use <filesystem> to determine if file is executable
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>
.我想知道是否有办法使用新的 C++17/20
#include <filesystem>
确定目录中的文件是否可执行。 I do not want to use Boost.我不想使用 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.我知道如何使用
stat
、 st_mode
和S_IXUSR
完成此操作,但我还没有找到使用纯 C++17/20 的方法。
Check execution permissions , that is owner_exec
, group_exec
and other_exec
attributes of the corresponding std::experimental::filesystem::permissions
struct.检查执行权限,即对应
std::experimental::filesystem::permissions
结构的owner_exec
、 group_exec
和other_exec
属性。 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).根据您对当前用户的了解(是文件的当前用户所有者,在文件的用户组中)检查这些。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.