lundi 4 septembre 2017

sort subfolders of Directory numerically using boost::filesystem

I am using the same example as in the boost tutorials. But since my files are numbered (1,20,23,..). The code fails(ex. 20<7). Is there a way to compare the directory_iteration numerically. Here is a snippet of the code

else if (is_directory(p))      // is p a directory?
      {
        cout << p << " is a directory containing:\n";

        typedef vector<path> vec;             // store paths,
        vec v;                                // so we can sort them later

        copy(directory_iterator(p), directory_iterator(), back_inserter(v));

        sort(v.begin(), v.end());             //  **I want to sort this numerically**

        for (vec::const_iterator it(v.begin()), it_end(v.end()); it != it_end; ++it)
        {
          cout << "   " << *it << '\n';
        }
      }

Aucun commentaire:

Enregistrer un commentaire