2012-03-13 3 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