Skip to content

Instantly share code, notes, and snippets.

@DankRank
Created January 9, 2017 10:06
Show Gist options
  • Save DankRank/801d047f76a6b239467ee99fb6b4ff3d to your computer and use it in GitHub Desktop.
Save DankRank/801d047f76a6b239467ee99fb6b4ff3d to your computer and use it in GitHub Desktop.
_findfirst/_findnext wrapper
class FindFile {
std::vector<_finddata_t> data;
typedef std::vector<_finddata_t>::iterator iterator;
public:
explicit FindFile(std::string s) {
data = std::vector<_finddata_t>();
_finddata_t d;
intptr_t ptr = _findfirst(s.c_str(), &d);
if (ptr != -1) {
do {
data.push_back(d);
} while (_findnext(ptr, &d) != -1);
_findclose(ptr);
}
else if (errno != ENOENT) {
perror("Can't findfirst");
// TODO: throw some exception here
}
}
iterator begin() { return data.begin(); }
iterator end() { return data.end(); }
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment