Listing files in a folder

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

Join Date: Apr 2004
Posts: 353
Reputation: Asif_NSU is on a distinguished road 
Solved Threads: 2
Asif_NSU's Avatar
Asif_NSU Asif_NSU is offline Offline
Posting Whiz

Listing files in a folder

 
1
  #1
Apr 5th, 2006
I am trying to access files in a folder. The folder name and location will be given - the program will search inside the files in that folder for a specific pattern(yup like grep). However, I am not sure how to actually let my program know what are the files available and access them one by one.

I could use pipe in unix or linux. As for Win XP I could only think of using the system("dir > tmpfilename") and thus saving the output it into a temporary file. Then taking the file names from that file.

Please let me know if anyone of you have a better idea as how to do the job. I cannot use win32 because the program would be used as an example in a class introducing the C programming language. So it means no C++ as well. Is there any way to make the code portable(I doubt)?
"He who mixes with people and endures the harm they do is better than he who does not mix and endures." (Tirmidhi)
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,378
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1466
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: Listing files in a folder

 
0
  #2
Apr 5th, 2006
On MS-Windows, use FindFirstFile() and FindNextFile(). There are lots of examples how to use those two functions floating around, just use google to search for them.

>>I cannot use win32 because the program would be used as an example in a class introducing the C programming language

How to get those filenames is an os-specific task -- you will have to use win32 api functions. Yes, they can be used in console applications, just include windows.h. And it does not require any knowlege of c++. But it does require a little more then absolute beginner's knowledge. Need to know about loops, and structures and character arrays. If that is too much then you probably should pick a different example.
Reply With Quote Quick reply to this message  
Reply

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



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



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC