Boost Iostream reading many files in a folder
Mar 15, 2012 at 6:34pm UTC
Hello I'm trying to read a folder for its files using boost iostreams
this is my current code
1 2 3 4 5 6 7 8 9 10
typedef ex::container_source<string>
string_source;
string input = "hello" ;
string output;
io::stream<string_source> in(input);
getline(in, output);
assert(input == output);
cout << output << endl;
but I don't know what code to add to make it read a bunch of files in a folder of a certain extension specified like .obj.
Mar 15, 2012 at 9:54pm UTC
I don't know much about boost::iostream, but here's something from boost::filesystem that is simple and does what your asking.
1 2 3 4 5 6 7 8 9 10 11 12 13 14
#include <boost/filesystem.hpp>
#include <iostream>
namespace fs = boost::filesystem;
int main()
{
fs::path someDir("c:\\Windows\\System32" );
fs::directory_iterator end_iter;
for (fs::directory_iterator dir_iter(someDir); dir_iter != end_iter; ++dir_iter)
if (dir_iter->path().extension() == ".dll" )
std::cout << dir_iter->path().leaf() << std::endl;
return 0;
}
Last edited on Mar 15, 2012 at 9:57pm UTC
Mar 15, 2012 at 11:02pm UTC
I tried
1 2 3 4 5 6 7 8 9
namespace fs = boost::filesystem;
fs::path someDir("textfolder" );
fs::directory_iterator end_iter;
for (fs::directory_iterator dir_iter(someDir); dir_iter != end_iter; ++dir_iter)
if (dir_iter->path().extension() == ".txt" )
std::cout << dir_iter->path().leaf() << std::endl;
and it didn't cout anything to cmd ? what could it be the folder name or something I'm missing in the code
Last edited on Mar 15, 2012 at 11:06pm UTC
Mar 16, 2012 at 6:24am UTC
If textfolder is a folder in your current directory then use: "./textfolder"
instead. The ./ means current directory. ../ means directory above. if you have just / that is the root directory in unix/linux.
Topic archived. No new replies allowed.