c++ - cpp 进程无法访问该文件,因为它正被另一个进程使用

标签 c++ c++17

请帮帮我....

我想显示并返回我的一些文件的路径。

但不幸的是它没有返回所有文件的路径,

请看下面的照片

click here !

我的代码:

const std::filesystem::directory_options options = (
    std::filesystem::directory_options::follow_directory_symlink |
    std::filesystem::directory_options::skip_permission_denied
    );

try
{
    for (const auto& dirEntry :
        std::filesystem::recursive_directory_iterator("C:\\",
            std::filesystem::directory_options(options)))
    {

        std::cout << dirEntry.path().u8string() << std::endl;

    }

}
catch (std::filesystem::filesystem_error & fse)
{
    std::cout << fse.what() << std::endl;
}

错误:

状态: 该进程无法访问该文件,因为它正被另一个进程使用。例如: "C:\pagefile.sys"

问题是什么?

如何拒绝这个错误?

最佳答案

我是这样解决的:

if (!strstr(dirEntry.path().filename().u8string().c_str(), ".sys"))
{
    std::cout << dirEntry.path().u8string() << std::endl;
}

关于c++ - cpp 进程无法访问该文件,因为它正被另一个进程使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59038530/

相关文章:

c++ - 使用 c++17 算法并行化一个简单的循环

c++ - 初始化类成员的更好做法是什么?

javascript - 使用 cocos2d-js 设置 jsbindings 类的正确方法是什么?

C++模板矩阵类——方阵特化

c++ - 函数模板特化生成链接错误

c++ - 使用全局 std::array 引用作为模板参数时如何简化参数?

c++ - _Not_fn 函数调用运算符的 noexcept 说明符

c++ - 如何通过 Outlook 扩展 Windows 桌面搜索

c++ - 使用 MFC 编辑控件中的 block 字符(仅限 float 的示例)

C++——多重继承