finding files with extensions

M

mohi

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
 
S

sk_usenet

mohi said:
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

Do you necessarily have to do it in C++? Have you considered some scripting
language like Perl?
 
J

Jim Langston

mohi said:
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

If boost doesn't work for you, then you will need to go with an OS specific
solution so will need to ask in a newsgroup dedicated to your OS.
If you are using windows check your documentation for findfirst
 
H

hurcan solter

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
 
M

mohi

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 thefiles
in it and process certainfileswith someextensionslike .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 thefilesending 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

thank you solter for your reply but this code is giving a lot of
compilation errors which im not able to understand
can you please help how to fix it ,
i think all includes are recognized nicely but please give the
required compile command also (im using linux:gnu gcc on comand line
on my fedora 8)

thank you mohan gupta
 
M

mohi

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 thefiles
in it and process certainfileswith someextensionslike .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 thefilesending 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

hank you solter for your reply but this code is giving a lot of
compilation errors which im not able to understand
can you please help how to fix it ,
i think all includes are recognized nicely but please give the
required compile command also (im using linux:gnu gcc on comand line
on my fedora 8)

thank you mohan gupta
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,812
Messages
2,569,694
Members
45,478
Latest member
dontilydondon

Latest Threads

Top