Help with Searching files in Directories

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: May 2005
Posts: 10
Reputation: usausa is an unknown quantity at this point 
Solved Threads: 0
usausa's Avatar
usausa usausa is offline Offline
Newbie Poster

Help with Searching files in Directories

 
0
  #1
May 19th, 2005
I am trying to search for files in Directories.
like, i have 10 directories..... and consider directory 1, which has 2 files..
this is same with all the files...
i want to get a string from each of these files from 10 directories... to be written to a seperate file, in C++.
I have been trying to do this.... any help will be greatly appreciated.
Thank you
Reply With Quote Quick reply to this message  
Join Date: May 2005
Posts: 232
Reputation: Dogtree is an unknown quantity at this point 
Solved Threads: 3
Dogtree's Avatar
Dogtree Dogtree is offline Offline
Posting Whiz in Training

Re: Help with Searching files in Directories

 
0
  #2
May 19th, 2005
Can you get a string from one file? If so then can you get a string from more than one file in the same directory? Do you have to search for the files according to some pattern, or do you have a list of filenames? I see this question a lot, and nobody gives enough detail. I need to know what you already know how to do. If you don't know how to open and read a file then my answering the question assuming your problem is with reading from multiple directories wouldn't help much. If you don't know how to open and read from different directories then I need to know what operating system and compiler you use because there's no portable solution for that problem.
Reply With Quote Quick reply to this message  
Join Date: May 2005
Posts: 10
Reputation: usausa is an unknown quantity at this point 
Solved Threads: 0
usausa's Avatar
usausa usausa is offline Offline
Newbie Poster

Re: Help with Searching files in Directories

 
0
  #3
May 19th, 2005
Yes, i can get the string i want from one file, and from multiple files in one directory.
i have to search for the files, based on one String, and then get the data from those files.

i worked with files before, but no with searching for files in directories and arranging them in an array.
coz, there is parent directory, which has subfolders.these subfolders has files.
the OS is Winxp, VC++ compiler.
Reply With Quote Quick reply to this message  
Join Date: May 2005
Posts: 232
Reputation: Dogtree is an unknown quantity at this point 
Solved Threads: 3
Dogtree's Avatar
Dogtree Dogtree is offline Offline
Posting Whiz in Training

Re: Help with Searching files in Directories

 
0
  #4
May 19th, 2005
In that case the Win32 API would probably be your easiest solution. You can start browsing from here.
Reply With Quote Quick reply to this message  
Join Date: May 2005
Posts: 10
Reputation: usausa is an unknown quantity at this point 
Solved Threads: 0
usausa's Avatar
usausa usausa is offline Offline
Newbie Poster

Re: Help with Searching files in Directories

 
0
  #5
May 20th, 2005
how about this function... any further help plzz

  1. private void GetFileInDirectory()
  2. {
  3. textfile = new string[200];
  4. try
  5. {
  6. string [] files;
  7. string path = currentPictureFile.Substring(0, currentPictureFile.LastIndexOf("\\") + 1);
  8.  
  9. if ( Directory.Exists(path) )
  10. {
  11. files = Directory.GetFiles(path);
  12. int i = 0;
  13. foreach ( string fileName in files )
  14. {
  15. int lastIndex = fileName.LastIndexOf(".");
  16. if ( fileName.Length - lastIndex - 1 == 3 )
  17. {
  18. string ext = fileName.Substring(lastIndex + 1, 3).ToUpper();
  19. if ( (ext.Equals("txt" ) )
  20. {
  21. textfile[i++] = fileName;
  22. }
  23. }
  24.  
  25. }
  26.  
  27. }
  28. }
  29.  
  30. catch (IOException ioE)
  31. {
  32. MessageBox.Show("Error - wrong path");
  33. }
  34.  
  35. catch (UnauthorizedAccessException unE)
  36. {
  37.  
  38. }
  39. }
Reply With Quote Quick reply to this message  
Join Date: May 2005
Posts: 232
Reputation: Dogtree is an unknown quantity at this point 
Solved Threads: 3
Dogtree's Avatar
Dogtree Dogtree is offline Offline
Posting Whiz in Training

Re: Help with Searching files in Directories

 
0
  #6
May 20th, 2005
Uh, that's not C++, it's Java.
Reply With Quote Quick reply to this message  
Join Date: May 2005
Posts: 10
Reputation: usausa is an unknown quantity at this point 
Solved Threads: 0
usausa's Avatar
usausa usausa is offline Offline
Newbie Poster

Re: Help with Searching files in Directories

 
0
  #7
May 20th, 2005
yeah... right...

i was trying to do it in C++... just found this piece of code from my frnd...

I have never worked with file search and directory structure

am very Stuck at this point... it wont let me further...

any help will be appreciated....

Thnx alotttttttttt in advance
Reply With Quote Quick reply to this message  
Join Date: Apr 2004
Posts: 4,416
Reputation: Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future 
Solved Threads: 248
Team Colleague
Dave Sinkula's Avatar
Dave Sinkula Dave Sinkula is offline Offline
long time no c

Re: Help with Searching files in Directories

 
0
  #8
May 20th, 2005
In another forum I posted a link to an FAQ: "Accessing a directory and all the files within it". Did you follow the link?
"One of the methods used by statists to destroy capitalism consists in establishing controls that tie a given industry hand and foot, making it unable to solve its problems, then declaring that freedom has failed and stronger controls are necessary." --Ayn Rand
Reply With Quote Quick reply to this message  
Join Date: May 2005
Posts: 10
Reputation: usausa is an unknown quantity at this point 
Solved Threads: 0
usausa's Avatar
usausa usausa is offline Offline
Newbie Poster

Re: Help with Searching files in Directories

 
0
  #9
May 20th, 2005
yes sir, i did that,...... but that doesnt work with VC++

i tried those... plz help
Reply With Quote Quick reply to this message  
Join Date: May 2005
Posts: 232
Reputation: Dogtree is an unknown quantity at this point 
Solved Threads: 3
Dogtree's Avatar
Dogtree Dogtree is offline Offline
Posting Whiz in Training

Re: Help with Searching files in Directories

 
0
  #10
May 20th, 2005
Another option if MSDN scares you is to download the Boost::filesystem library. If you can figure out how to build it and link with it then writing your program would be a breeze. But I still recommend using the Win32 API, and my link is a great start.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the C++ Forum
Thread Tools Search this Thread



Tag cloud for C++
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC