【问题标题】:c++ filesystem The system cannot find the path specifiedc++ filesystem 系统找不到指定的路径
【发布时间】:2019-11-29 10:13:57
【问题描述】:

真正的问题出在哪里? 此路径存在,但程序失败。

我想知道这个问题的原因?

    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:\\Users\\myuser",
            std::filesystem::directory_options(options)))
    {

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


    }

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

C:/Users/myuser/Contacts/{857B728B-5B31-4F94-B832-522DF52E4335}/VertiPaq_68547BCEF3A344CDA3CE/724C7FC1B3284E4BBE1C.3.db/Model.193.cub/Cuentas por Cobrar_f7776207-ea17-4002-8801-3561d1b2d1fc. 92.det/Cuentas 由 Cobrar_f7776207-ea17-4002-8801-3561d1b2d1fc.23.prt recursive_directory_iterator::operator++: 系统找不到指定的路径。

【问题讨论】:

标签: c++ path iterator


【解决方案1】:

问题可能是std::filesystem 只能是实现实际文件系统的可移植抽象。根据您的路径,我假设您使用的是 Microsoft Windows。

所以问题很清楚:您的路径很长:它的 260 个可见字符加上不可见的 end/null/termination 字符。这比MAX_PATHsee this documentation.

在 Windows API 中(下面将讨论一些例外情况 段落),路径的最大长度为 MAX_PATH,即 定义为 260 个字符。本地路径按以下顺序构建:驱动器号、冒号、反斜杠、由反斜杠分隔的名称组件和终止空字符。

【讨论】:

  • 谢谢,请问如何解决这个问题?
  • 不使用这么长的路径,或者需要 Windows 10 版本 1607 或更高版本并直接使用 Windows API,以及我发布的链接中描述的启用所需的所有额外步骤,这太多了对于一个 SO 帖子。
  • 有什么办法可以跳过吗?
  • 正如我所说的唯一选择:A)不要使用这么长的路径 B)不要使用 Windows C)在提到的 Windows 10 版本和链接的步骤中使用 D)使用其他一些语言/runtime/library 使用其他 API 或为您执行 C 的步骤(如果有)
  • D2) 尝试发布链接中的 Unicode 变通方法请不要忘记接受答案。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-02-23
  • 2018-12-12
  • 2016-04-23
  • 2017-01-04
  • 2014-04-24
相关资源
最近更新 更多