2012-03-13 11 views
1

QDirIteratorを使用するときにディレクトリを除外/フィルタリングできるかどうか疑問に思っています。私はそれをスキップする/それを完全に無視したいと思います。QtでQDirIteratorを使用しているときにフィルタリング/除外

 QString SkipThisDir = "C:\stuff"; 

     QDirIterator CPath(PathToCopyFrom, QDir::AllEntries | QDir::NoSymLinks, QDirIterator::Subdirectories); 


      while(CPath.hasNext()) 
      { 
       CPath.next(); 
       //DoSometing 
      } 

答えて

2

具体的には、QDirIteratorのAPIには何も表示されません。しかし、次のような単純なものが機能します。

while (CPath.hasNext()) 
{ 
    if (CPath.next() == SkipThisDir) 
     continue; 
    //DoSomething 
} 
+0

これは機能しているようです。ありがとう! – Darren

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 
} 
+0

それは働いているようです。ありがとう! – Darren

関連する問題