473,386 Members | 1,820 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

finding files with extensions

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
Jun 27 '08 #1
5 4442
"mohi" <mo**********@gmail.comwrote in message
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?

--
http://techytalk.googlepages.com
Jun 27 '08 #2
mohi wrote:
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

--
Jim Langston
ta*******@rocketmail.com
Jun 27 '08 #3

>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

Jun 27 '08 #4
On Apr 24, 6:01 am, hurcan solter <hsol...@gmail.comwrote:
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
Jun 27 '08 #5
On Apr 24, 6:01 am, hurcan solter <hsol...@gmail.comwrote:
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
Jun 27 '08 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: DJ Craig | last post by:
I'm trying to create a .txt file on my server that will log the IP, user agent, and referrer of people who access it, and send back different contents based on the user agent. The file has to have...
5
by: hokiegal99 | last post by:
Hi, I have a working Python script that renames files that don't currently have PC based file extensions. For example, if there is a MS Word file that does not have '.doc' on the end of it, the...
6
by: Martin Bless | last post by:
The good news: Along with Python-2.4 comes really good news to Windows users. Yes, you now CAN build extension modules yourself using the SAME C++ compiler and linker Python is built with...
22
by: Tony Houghton | last post by:
I'm using pygame to write a game called Bombz which needs to save some data in a directory associated with it. In Unix/Linux I'd probably use "~/.bombz", in Windows something like "C:\Documents...
4
lucas911
by: lucas911 | last post by:
I'm sure that this is possible: I have a parent directory that has sub directories. Each sub directory will store certain files in certain formats, i.e. i have 1 directory for excel, 1 for...
8
by: SAIRAAM | last post by:
hi all i am right now examing one of the project thats avaliable.in which they have taken single log file as input. the code for it is given below. Private Sub...
6
by: begum | last post by:
HI everybody; I have problem about selecting files in my main file. I have to find the files whose ending INF. What Can I do?Can anybody help me? using System; using...
2
by: datamonk | last post by:
I am working on a package in SSIS that needs to check a directory to see if any files that begin with a three character string (PDE) exist, and set the value of a variable accordingly to determine...
1
by: avik1612 | last post by:
Hi, I have created a program to find text files in a particular directory or folder. and to find a particular word in that files i finding it difficult to put the list in an array and finding...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.