在Qt中使用QDirIterator时筛选/排除目录
Filter/Exclude a directory when using QDirIterator in Qt
我想知道在使用QDirIterator时是否可以排除/筛选目录。我希望它跳过它/完全忽略它。
QString SkipThisDir = "C:stuff";
QDirIterator CPath(PathToCopyFrom, QDir::AllEntries | QDir::NoSymLinks, QDirIterator::Subdirectories );
while(CPath.hasNext())
{
CPath.next();
//DoSometing
}
我在API for QDirIterator中看不到任何特定的功能。然而,像下面这样简单的事情会起作用。
while (CPath.hasNext())
{
if (CPath.next() == SkipThisDir)
continue;
//DoSomething
}
首先,您必须在SkipThisDir
中再添加一个反斜杠才能对其进行转义。
Second you could do a check at the beginning of the while loop and if the current folder is the one you want to skip you could continue to the next directory.
QString SkipThisDir = "C:\stuff";
QDirIterator CPath(PathToCopyFrom, QDir::AllEntries | QDir::NoSymLinks,
QDirIterator::Subdirectories );
while(CPath.hasNext())
{
QString currentDir = CPath.next();
if (currentDir == SkipThisDir)
continue;
//DoSometing
}
相关文章:
- Geeksforgeeks C 程序故障排除:IEE 754 表示法为十进制
- 输入验证以筛选出字符、字符串和一系列整数
- 如何从整个磁盘中排除要装载的一个文件
- 参数包中的筛选器类型
- 如何进行故障排除:未定义对"非虚拟 thunk to ..."的引用
- 如何在 C++ 的输出中排除 SENTINEL 值?
- 针对代码::块设置的 SFML 故障排除
- 筛选 QFileDialog 中显示的目录
- 筛选嵌套的动态元组(元组的动态元组)
- 如何从结构列表中筛选信息
- 如何在 boost::spirit::qi 中将某些语义操作排除在 AST 之外
- C++:如何在从给定缓存中排除数字的同时生成随机数
- 通过QLineEdit筛选查询并更新QSqlQueryModel
- 遍历列表包含排除最后一个元素的内容
- C++排除通过派生类中的基类继承的类
- 在创建共享库时,是否可以明确地排除某些类
- 如何从所选目录(位于listWidget中)中筛选图像文件
- 对"无效的抽象返回类型"进行故障排除
- 需要帮助对内存泄漏源进行故障排除 - C++
- 在Qt中使用QDirIterator时筛选/排除目录