Search files/folders in a directory

and then save the found things in a vector or array.

Can it be done?

I have read the "Input/Output with files" but I haven't found anything about searching.
try looking up file searching algorithms.
The boost::filesystem:: library can help you with this. Otherwise you'll need to interface with the windows or linux APIs directly. There is nothing in std:: that does this.

If you did use boost, you would do something like this:
1
2
3
4
5
6
7
8
9
10
11
12
13
#include <iostream> 
#include <boost/filesystem.hpp>

int main()
{
	namespace fs = boost::filesystem;

	fs::path WorkingPath("c:\\temp\\"); // Desired directory
	fs::directory_iterator StartIter(WorkingPath), EndIter; // This is automatically set to the end of a directory

	for (; StartIter != EndIter; ++StartIter) // Iterate through all files in this folder
		std::cout << StartIter->path().leaf() << std::endl; // Output filenames
}


Reference:
http://www.boost.org/doc/libs/1_49_0/libs/filesystem/v3/doc/index.htm
Last edited on
Topic archived. No new replies allowed.