473,668 Members | 2,398 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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::filesyst em 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 4473
"mohi" <mo**********@g mail.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::filesyst em 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*******@rocke tmail.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::filesyst em 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::filesyst em;
int main( int argc, char* argv[] )
{
fs::path p(".");
boost::regex e(".(cpp|sln)$" );

fs::directory_i terator dir_iter(p), dir_end;
std::string filename;
for(;dir_iter != dir_end; ++dir_iter)

{
filename=dir_it er->leaf();
std::cout<<file name<<std::endl ;
if (boost::regex_s earch(filename, e))
{
std::cout<<"Mat chFound:"<<file name<<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.HURC AN.Administrato r.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 certainfileswit h someextensionsl ike .txt, .doc
etc ..but i dont know about the actual file names only extension is
know
as "utab" suggested me to look at boost::filesyst em 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::filesyst em;

int main( int argc, char* argv[] )
{
fs::path p(".");
boost::regex e(".(cpp|sln)$" );

fs::directory_i terator dir_iter(p), dir_end;
std::string filename;
for(;dir_iter != dir_end; ++dir_iter)

{
filename=dir_it er->leaf();
std::cout<<file name<<std::endl ;
if (boost::regex_s earch(filename, e))
{
std::cout<<"Mat chFound:"<<file name<<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.HURC AN.Administrato r.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 certainfileswit h someextensionsl ike .txt, .doc
etc ..but i dont know about the actual file names only extension is
know
as "utab" suggested me to look at boost::filesyst em 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::filesyst em;

int main( int argc, char* argv[] )
{
fs::path p(".");
boost::regex e(".(cpp|sln)$" );

fs::directory_i terator dir_iter(p), dir_end;
std::string filename;
for(;dir_iter != dir_end; ++dir_iter)

{
filename=dir_it er->leaf();
std::cout<<file name<<std::endl ;
if (boost::regex_s earch(filename, e))
{
std::cout<<"Mat chFound:"<<file name<<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.HURC AN.Administrato r.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
1366
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 the ..txt extension because there are already links to the file on other web sites where I can't change the link URL. Is it possible to have PHP interpret files with extensions other than .php? It would also be useful for finding out when other...
5
2032
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 script will append that. The script also knows to *not* add an extension if the file already has one. Bascially, here's how I'm doing it: for fname in files: doc_id = string.find(file(os.path.join(root,fname),
6
6168
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 itself. Everything you need is available at no costs (except download hassle and installation time). Once your system is set up properly its just a matter of running 'python setup.py build'. No longer waiting for someone else to build binaries and a...
22
2671
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 And Settings\<user>\Applicacation Data\Bombz". There are plenty of messages in the archives for this group about how to find the correct location in Windows, but what about Mac OS? There I don't know the correct location for this sort of thing at...
4
1908
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 word... and so on. As an example i have a sub directory called FinalDocumentation that will store excel files based on my final documentation template. Every file will have the same convention i.e. TXX_08-Mar-2007_Final_Documentation_Joe_Smith.xls...
8
1775
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 cmdInputBrowse_Click() On Error GoTo ErrorLine Dim fname As String Dim fso As New FileSystemObject Dim ext, newext As Variant Dim stat, i As Integer
6
1974
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 System.Collections.Generic; using System.Text; using System.IO; namespace ConsoleApplication1
2
1466
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 which path the package should follow next. Here is the code I am using. I found it on a similar thread in this forum. The code runs without error but does not update the variable to 1 when a file exists. Any suggestions? Dim AllFiles()...
1
1358
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 the words I have pasted the code below
0
8381
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
8586
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8658
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6209
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5681
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4205
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4380
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2792
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2026
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.