Created
January 16, 2016 01:14
-
-
Save psychoss/ef24c989b0c717452c8e to your computer and use it in GitHub Desktop.
C++
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <sys/types.h> | |
#include <dirent.h> | |
#include <errno.h> | |
#include <vector> | |
#include <string> | |
#include <iostream> | |
using namespace std; | |
/*function... might want it in some class?*/ | |
int getdir (string dir, vector<string> &files) | |
{ | |
DIR *dp; | |
struct dirent *dirp; | |
if((dp = opendir(dir.c_str())) == NULL) { | |
cout << "Error(" << errno << ") opening " << dir << endl; | |
return errno; | |
} | |
while ((dirp = readdir(dp)) != NULL) { | |
files.push_back(string(dirp->d_name)); | |
} | |
closedir(dp); | |
return 0; | |
} | |
int main() | |
{ | |
string dir = string("."); | |
vector<string> files = vector<string>(); | |
getdir(dir,files); | |
for (unsigned int i = 0;i < files.size();i++) { | |
cout << files[i] << endl; | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment