- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在遍历一个目录,当某个项目符合某些条件时,我将其删除。我可以在循环内安全地执行此操作,还是必须将路径保存在数组中并稍后删除?
我在boost::filesystem docs中没有找到相关信息.
最佳答案
引用 docs of boost::filesystem::directory_iterator 所附注释的第一部分(重点是我自己的):
Programs performing directory iteration may wish to test if the path obtained by dereferencing a directory iterator actually exists. It could be a symbolic link to a non-existent file. Programs recursively walking directory trees for purposes of removing and renaming entries may wish to avoid following symbolic links.
我清楚地意识到,为了删除文件而迭代目录是官方支持的用例,因此不会使迭代器无效。另外,引用该注释的第二部分:
If a file is removed from or added to a directory after the construction of a directory_iterator for the directory, it is unspecified whether or not subsequent incrementing of the iterator will ever result in an iterator whose value is the removed or added directory entry. See ISO/IEC 9945 readdir_r().
这是一个非常具体的声明,关于在迭代目录时是否会出现已删除的文件。再说一遍,我明白迭代过程本身在任何情况下仍然有效。
请注意ISO/IEC 9945有类似的措辞。
关于iterator - boost::filesystem::directory_iterator 是否因删除而失效?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13513369/
自从我使用 C++ 以来已经有一段时间了,请原谅我的新手问题。 我编写了以下代码来获取目录内容的列表,它运行良好: for (directory_iterator end, dir("./");
我正在尝试遍历目录并读取其中的图像,同时允许跳过每第 n 个文件。 我的代码目前看起来像这样: // Count number of files in directory and reserve me
这是我的代码: #include #include int main(int argc, char *argv[]) { auto iter = std::filesystem::dire
编辑:我使用的是 std::tr2::sys 而不是 boost 的文件系统 我正在开发一个简单的应用程序,它可以扫描计算机上的目录并返回有关这些文件的统计信息。可以通过两种方式调用扫描:递归和非递归
我想重命名目录中的文件。目录中有 52 个文件夹。每个文件夹都有不同的名称,每个文件夹中有大约 40 个文件。我想提取特定文件夹的名称并将该名称附加到该特定文件夹中的文件名称。 当每个文件夹中只有 3
所以我写了一个小程序来试用 Boost Filesystem。我的程序将写入当前路径中有多少个文件,然后是文件名。这是我的程序: #include #include using namespace
我一直在尝试使用通过快速谷歌搜索找到的这个示例遍历目录: namespace bf = boost::filesystem; bf::path p("somedir"); bf::directory_
我已经在 directory_iterator page 上复制了示例代码,所以这就是我所拥有的: #include "pch.h" //for visual studios benefit #inc
我有以下代码: for (const auto& x : std::filesystem::directory_iterator(dir)) { // do stuff with x } di
我正在遍历一个目录,当某个项目符合某些条件时,我将其删除。我可以在循环内安全地执行此操作,还是必须将路径保存在数组中并稍后删除? 我在boost::filesystem docs中没有找到相关信息.
有些东西没有意义。根据我读过的内容,你使用 std::filesystem 是这样的: #include #include #include int main() { auto it
许多人(例如 1 、 2 )询问如何获得 std::filesystem::directory_iterator去工作,但在我读完这些之后我仍然遇到了麻烦。 我正在尝试构建一个小型静态库。在将目录迭代
我在 gcc 6.3.1 中使用实验性 std::filesystem 实现,遇到了一些关于 std::experimental::filesystem::directory_iterator #in
以下代码递归地遍历给定目录并每次以相同顺序打印其内容。 是否可以改变目录迭代器以随机方式打印目录内容(而不是使用 vector 存储结果然后随机打印 vector 内容)? #include #in
我正在编写一个程序,它获取目录中的所有文件名并将它们放入一个数组中。我遇到的问题是 operator++() 显示错误并且不会增加迭代器。任何帮助将不胜感激。 #include #include
我知道这听起来很愚蠢,但看看这个简单的例子(工作目录应该有多个项目): #define BOOST_FILESYSTEM_VERSION 3 #include #include int main(
我正在尝试使用其 insert(const_iterator pos, InputIt first, InputIt last) 将转换后的目录条目范围插入 vector 中成员函数模板。 不幸的是,
我正在尝试获取最后一个文件名。 下面的代码非常优雅。但它正在遍历目录中的所有文件。 是否可以在不迭代的情况下获取最后一个文件? #include std::string latestFileName
我正在使用 boost 的文件系统和 std::max_element() 来查找给定目录中名称最长的文件: #include #include #include #include #incl
我正在尝试学习如何使用 Boost C++ 库,但我遇到了一个问题。运行以下 boost::filesystem 教程代码时: #include #include using std::cout;
我是一名优秀的程序员,十分优秀!