我想知道在使用QDirIterator时是否可以排除/过滤目录。我希望它跳过它/完全忽略它。
QString SkipThisDir = "C:\stuff";
QDirIterator CPath(PathToCopyFrom, QDir::AllEntries | QDir::NoSymLinks, QDirIterator::Subdirectories );
while(CPath.hasNext())
{
CPath.next();
//DoSometing
}
答案 0 :(得分:2)
我没有在QDirIterator的API中看到任何符合您需要的内容。但是,下面这么简单的事情就可以了。
while (CPath.hasNext())
{
if (CPath.next() == SkipThisDir)
continue;
//DoSomething
}
答案 1 :(得分:0)
首先,您必须向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
}