Created
January 9, 2017 10:06
-
-
Save DankRank/801d047f76a6b239467ee99fb6b4ff3d to your computer and use it in GitHub Desktop.
_findfirst/_findnext wrapper
This file contains 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
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