Go back to Richel Bilderbeek's homepage.

Go back to Richel Bilderbeek's C++ page.

 

 

 

 

 

(C++) GetFoldersInFolder

 

GetFoldersInFolder is a file I/O code snippet to obtain all folder names in a folder.

 

 

 

 

 

Qt GetFoldersInFolder using Qt

 

#include <QDir>
#include <QFileInfoList>

//From http://www.richelbilderbeek.nl/CppGetFoldersInFolder.htm
const std::vector<std::string> GetFoldersInFolder(const std::string& folder)
{
  //Obtain all folders
  QDir dir(folder.c_str());
  dir.setFilter(QDir::NoDotAndDotDot | QDir::Dirs);
  const QFileInfoList list = dir.entryInfoList();

  //Convert QFileInfoList to std::vector<std::string> of filenames
  std::vector<std::string> v;
  const int size = list.size();
  for (int i = 0; i != size; ++i)
  {
    v.push_back(list.at(i).fileName().toStdString());
  }
  return v;
}

 

 

 

 

 

Go back to Richel Bilderbeek's C++ page.

Go back to Richel Bilderbeek's homepage.

 

Valid XHTML 1.0 Strict