std::filesystem::copy throws filesystem_error
std::filesystem::copy throws filesystem_error
正在尝试运行此代码:
filesystem::copy_options copyOptions = filesystem::copy_options::skip_existing | filesystem::copy_options::recursive | filesystem::copy_options::directories_only;
filesystem::copy(pathA, pathB, copyOptions);
第一次尝试是成功的,完全按照我的意愿和预期进行。。。第二次尝试(在创建pathB结构之后(失败,并出现以下错误:
filesystem error: cannot copy: File exists
[C:UsersSmithDocumentsProjectsProjectAbin..pathA]
[C:UsersSmithDocumentsProjectsProjectAbin..pathB]
我的期望是,使用skip_existing或overwrite_existing不应该引发此错误。如何使用这种复制方法而不必每次使用前都删除路径B?
链接到cppreference我正在看
您需要使用标志std::filesystem::copy_options::overwrite_existing
。
这解决了你的问题。
我遇到了这个确切的问题,结果发现当两条路径完全相同时就会发生。在我的例子中,用户设置输出路径,然后设置从源目录复制的配置文件。如果用户将输出路径设置为源目录,则该命令最终将类似于
fs::copy("path/to/config.txt", "path/to/config.txt", fs::copy_options::update_existing);
即使使用update_existing
或overwrite_existing
,也会抛出错误
terminate called after throwing an instance of 'std::filesystem::__cxx11::filesystem_error'
what(): filesystem error: cannot copy: File exist
相关文章:
- "error: no matching function for call to"构造函数错误
- C++,OpenCV,尝试显示图像时"OpenCV(4.3.0) Error: Assertion failed (size.width>0 && size.height>0)"此错误
- 带有特殊路径部分的"std::filesystem::weakly_canonical"失败
- 使用 LuaBridge 将 LuaJIT 绑定到C++会导致"PANIC: unprotected error"
- OpenMP卸载说'fatal error: could not find accel/nvptx-none/mkoffload'
- std::filesystem::copy throws filesystem_error
- C++将目录中的所有文件与::filesystem进行比较
- C++错误:"error: int aaa::bbb is protected within this context"
- 尝试链接我的着色器时,我收到错误代码"error c5145 must write to gl_position"
- C++,在int数组中输入字符串或字符会输出0,而不是ascii或error
- 使用 cmake 的 LLVM 构建在 tsan_libdispatch_mac.cc 期间失败; "Error: conflicting types for ..."
- C++ "error: invalid use of void expression"
- struct.error:解压缩 C++ 结构时,解包需要 288 字节的缓冲区
- 如何修复"error: ‘_1’ was not declared in this scope"?
- <filesystem> 在 clang 6 和 10 上 #include 错误
- 在带有尾部斜杠的路径上返回 std::filesystem::create_directories() 的值
- 从不同目录执行时"symbol lookup error:",否则从构建目录执行时按预期工作
- 对象声明中的模板"error: expected expression"
- 在C++中使用 Catch 测试框架编译错误"error: expected ';' at end of declaration list"
- 为什么该输出是 boost 程序 (boost::filesystem) 中的"Bus error: 10"?