简体   繁体   English

C++17/20 - 使用<filesystem>确定文件是否可执行</filesystem>

[英]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.我知道如何使用statst_modeS_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_execgroup_execother_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.

相关问题 如何使用文件系统库获取“真实”文件大小? (C ++ 17) - How to get “true” file size with filesystem library? (C++17) C++17 的编译错误<filesystem>在 MinGW 上 - Compilation errors for C++17 <filesystem> on MinGW 错误使用<filesystem> C++17 - Errors using <filesystem> C++17 c ++ 17 `filesystem` 不是命名空间名称 - c++17 `filesystem` is not a namespace-name 将 CMake 配置为在 C++20 中编译,但可执行文件在 C++17 中编译 - Configured CMake to compile in C++20 but the executable compiles in C++17 如何在 C++17 中不包含完整文件系统 header 的情况下使用文件系统的 class 路径? - How to use the class path of filesystem without including the complete filesystem header in C++17? 是否可以使用标准的 C++17<filesystem> C++ 编译器模式下的 Zig 功能?</filesystem> - Is it possible to use the standard C++17 <filesystem> facilities with Zig in C++ compiler mode? C++17,英特尔 C++ 编译器:在 Z0F4137ED1502B5045DZ601 平台中使用文件系统 header 需要什么库? - C++17, Intel C++ compiler: what is the library needed to use filesystem header in windows 10 platform? C++ CodeBlocks 升级到 C++17 不能使用 std::filesystem - C++ CodeBlocks upgrade to C++17 can't use std::filesystem 为什么 Xcode 11 beta 不能使用 C++17<filesystem> 头? - Why Xcode 11 beta can't use C++17's <filesystem> header?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM