Monday, July 22, 2013

Return the list of sub folders from a directory in MFC

Below is the code snippet for a C++ function to return a list of sub folders from a directory in MFC:

#include "StdAfx.h"

void CAppUtilManager::GetSubFolders(const CString& parent_folder, CStringArray& sub_folders) const
{
 CFileFind fFind;
 BOOL bWorking=fFind.FindFile(parent_folder+_T("\\*.*"));

 while(bWorking==TRUE)
 {
  bWorking=fFind.FindNextFile();
  if(fFind.IsDots())
  {
   continue;
  }
  if(fFind.IsDirectory())
  {
   sub_folders.Add(fFind.GetFilePath());
  }
 }
 fFind.Close();
}

No comments:

Post a Comment