I'm working on designing a fast file read program in c/c++ that will retrieve each file in a directory in the order they were stored (created). Im using SFML and BOOST but my program will only return the files in a random order. I suppose this has to do with the b-tree ordering of the files? How do I get BOOST to return the files in the order in which they were created?
Here is the relevant part of the code:
#include <string>
#include <iostream>
#include <boost/filesystem.hpp>
#include "SFML/Graphics.hpp"
using std::cout;
using namespace boost::filesystem;
using namespace std;
....
path p (argv[1]);
....
for (directory_entry& x : directory_iterator(p)){
....
fullPathName = x.path().string();
filename = x.path().filename().string();
stem = x.path().stem().string();
seqnum = stem.substr(4,5);
extn = x.path().extension().string();
cout << fullPathName << ", " << filename << ", " << stem << ", " <<
seqnum << ", " << extn <<'\n';
}
Here is a sample output:
../takes/test/snap00179.png, snap00179.png, snap00179, 00179, .png ../takes/test/snap00321.png, snap00321.png, snap00321, 00321, .png ../takes/test/snap00094.png, snap00094.png, snap00094, 00094, .png ../takes/test/snap00121.png, snap00121.png, snap00121, 00121, .png ../takes/test/snap00026.png, snap00026.png, snap00026, 00026, .png ../takes/test/snap00024.png, snap00024.png, snap00024, 00024, .png ../takes/test/snap00155.png, snap00155.png, snap00155, 00155, .png ../takes/test/snap00065.png, snap00065.png, snap00065, 00065, .png ../takes/test/snap00015.png, snap00015.png, snap00015, 00015, .png ../takes/test/snap00075.png, snap00075.png, snap00075, 00075, .png ../takes/test/snap00017.png, snap00017.png, snap00017, 00017, .png