Reading files in folder

How do you read the files that are in the folder with the program in it?
Ala, I have a folder where there are various binaries in it with the data, and I want to access them, without having to type in the name of the file in advance.?
I'm pretty sure you would need API specific stuff for this. Although boost has a filesystem library you might want to look at.

http://www.boost.org/doc/libs/1_39_0/libs/filesystem/doc/index.htm
Something like this?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include <windows.h>  
#include <iostream>
#include <dirent.h>

using namespace std;

int main()
{
     DIR *D;
     struct dirent *Dirp;
     
     D = opendir("."); //"." Refers to the project location, any path can be placed here
     while ((Dirp = readdir(D))!= NULL)
     {
          cout << Dirp->d_name << endl;
     }
     system("PAUSE");
}


PS. Names without an extension are folders.
Also I would not recommend using a library for such a small task.
Last edited on
Topic archived. No new replies allowed.