943,735 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 10771
  • C++ RSS
Apr 5th, 2006
1

Listing files in a folder

Expand Post »
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)?
Similar Threads
Reputation Points: 113
Solved Threads: 3
Posting Whiz
Asif_NSU is offline Offline
353 posts
since Apr 2004
Apr 5th, 2006
0

Re: Listing files in a folder

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.
Sponsor
Team Colleague
Featured Poster
Reputation Points: 5608
Solved Threads: 2282
Retired and Enjoying Life
Ancient Dragon is online now Online
21,950 posts
since Aug 2005

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: Help, i suppose
Next Thread in C++ Forum Timeline: get werid error when splitting up my code





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC