How to fetch the list of folders from a given folder in C++?
How to fetch the list of folders from a given folder?
There is no way in standard C++ to do this... yet.
However, i recommend Boost.Filesystem. It is simple, sexy, portable and powerful, and will very likely be part of a future standard.
To get the list of folders in a folder using Boost.Filesystem:
However, i recommend Boost.Filesystem. It is simple, sexy, portable and powerful, and will very likely be part of a future standard.
To get the list of folders in a folder using Boost.Filesystem:
| Code: |
| typedef boost::filesystem::path path_type; // to save typing
std::vector<path_type> get_child_folders(path_type const& p) { typedef boost::filesystem::basic_directory_iterator<path_type> iter; // to save typing std::vector<path_type> folders; for (iter i = iter(p); i != iter(); ++i) if (is_directory(i->status())) folders.push_back(*i); return folders; } |
