>hello everyone
i m positing this again but can't help as im not finding any solution
to this .
my problem is i have to browse a directory to search for all the files
in it and process certain files with some extensions like .txt, .doc
etc ..but i dont know about the actual file names only extension is
know
as "utab" suggested me to look at boost::filesystem i tried there also
but cudn't get something which can solve this problem ,anyways thanx
utab 4 that
do anyone has any other suggestion.
all help is appreciated
mohan gupta
hmm why? it's pretty straightforward to iterate through a directory
with boost filesystem;
the code snippet below, iterates through the current directory and and
list the files ending with a .cpp or .sln;
#include "boost/filesystem/operations.hpp"
#include "boost/filesystem/path.hpp"
#include "boost/progress.hpp"
#include "boost/regex.hpp"
#include <iostream>
namespace fs = boost::filesystem;
int main( int argc, char* argv[] )
{
fs::path p(".");
boost::regex e(".(cpp|sln)$");
fs::directory_iterator dir_iter(p), dir_end;
std::string filename;
for(;dir_iter != dir_end; ++dir_iter)
{
filename=dir_iter->leaf();
std::cout<<filename<<std::endl;
if (boost::regex_search(filename,e))
{
std::cout<<"MatchFound:"<<filename<<std::endl;
}
}
}
which dumps the output below;
DATAS.ini
Debug
home.txt
out.txt
sil.cpp
Match Found : sil.cpp
sil.ncb
sil.sln
Match Found : sil.sln
sil.suo
sil.vcproj
sil.vcproj.HURCAN.Administrator.user