Skip to content

Instantly share code, notes, and snippets.

@SeanCline
Created February 28, 2013 03:31
Show Gist options
  • Save SeanCline/5053959 to your computer and use it in GitHub Desktop.
Save SeanCline/5053959 to your computer and use it in GitHub Desktop.
Playing with VS2012's preliminary implementation of <filesystem> before work on tr2 was halted.
#include <iostream>
#include <string>
#include <filesystem>
#include <vector>
#include <algorithm>
#include <exception>
using namespace std;
using namespace std::tr2::sys;
int main()
{
auto root = path("c:/");
vector<directory_entry> dir_list;
// Just to be sure ...
if (!is_directory(root)) {
cerr << "Directory \"" << root << "\" not found." << endl;
throw runtime_error("Damn.");
}
// Populate our vector with all child directories.
copy_if(directory_iterator(root), directory_iterator(), back_inserter(dir_list), [](directory_entry child) {
return is_directory(child.status());
});
// Print our list of subdirectories.
for (auto dir : dir_list)
{
cout << dir.path() << endl;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment