Recursive file search using C++ MFC?

后端 未结 5 1178
失恋的感觉
失恋的感觉 2020-12-06 14:45

What is the cleanest way to recursively search for files using C++ and MFC?

EDIT: Do any of these solutions offer the ability to use multiple filters through one pas

5条回答
  •  囚心锁ツ
    2020-12-06 15:16

    I know it is not your question, but it is also easy to to without recursion by using a CStringArray

    void FindFiles(CString srcFolder)
    {   
      CStringArray dirs;
      dirs.Add(srcFolder + "\\*.*");
    
      while(dirs.GetSize() > 0) {
         CString dir = dirs.GetAt(0);
         dirs.RemoveAt(0);
    
         CFileFind ff;
         BOOL good = ff.FindFile(dir);
    
         while(good) {
            good = ff.FindNextFile();
            if(!ff.IsDots()) {
              if(!ff.IsDirectory()) {
                 //process file
              } else {
                 //new directory (and not . or ..)
                 dirs.InsertAt(0,nd + "\\*.*");
              }
            }
         }
         ff.Close();
      }
    }
    

提交回复
热议问题