Iterating through a folder

I'm currently working on a personal project that I plan to make go through a number of files, taking data from each, perform statistical analysis, and organize the results and a decent manner. The issue I'm currently having is that I can't seem to figure out how to best approach the iteration. I have a fairly large number of files (apparently 2500...), and while the files themselves are a few megabytes large, I only need the first few kb's of information. The extraction I have no problem with. With regards to the iteration, I've looked into a few possibilities, but immediately felt like I was in over my head.

Let me also say that I have looked through the forums. I have seen the dirent.h and FindFirstFile posts, but honestly didn't understand them terribly well (meaning at all :P). If these are the only ways to approach the situation, I'd love a few examples that would be clear to a nooblet such as myself.

So yeah. Any help would be greatly appreciated.

Edit: Just realized I didn't mention this: Portability is important! Cross platform functionality isn't really needed, but I have plans for this to be distributed, so being portable is kinda sorta important.
Last edited on
If this is to be a one-off thing, what you could do is create a directory listing "manually" (you could use, say, UNIX find) and save it to a file. Then at run time all you need to do is read the file paths from that file.

Otherwise, I recommend boost::filesystem, specifically its directory_iterator.
boost.filesystem is the most portable solution today, and MSVC already ships it as a part of C++ standard library (it's planned for inclusion).

It has a directory_iterator and a recursive_directory_iterator: http://www.boost.org/doc/libs/release/libs/filesystem/doc/index.htm
Topic archived. No new replies allowed.