Skip to content

Instantly share code, notes, and snippets.

@luoyetx
Created July 21, 2014 07:21
Show Gist options
  • Save luoyetx/c6e754fcf257d82d2bc3 to your computer and use it in GitHub Desktop.
Save luoyetx/c6e754fcf257d82d2bc3 to your computer and use it in GitHub Desktop.
read Dir
#include <io.h>
/**
* readDir("F://pic", files, "jpg")
*/
bool readDir(string dirPath, vector<string>& files, string extension)
{
long fd;
_finddata_t fileInfo;
string matchPath = dirPath + "/*." + extension;
if ((fd=_findfirst(matchPath.c_str(), &fileInfo)) == -1) {
return false;
}
do {
files.push_back(fileInfo.name);
} while (_findnext(fd, &fileInfo) == 0);
_findclose(fd);
return true;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment