96 const std::string &extension) {
98 std::vector<std::string> filesInDir;
103 auto toWString = [](
const std::string &str) {
105 return std::wstring();
107 = MultiByteToWideChar(CP_UTF8, 0, str.c_str(), -1,
nullptr, 0);
109 wstr.resize(wcharCount);
110 MultiByteToWideChar(CP_UTF8, 0, str.c_str(), -1, &wstr[0], wcharCount);
113 auto toString = [](
const WCHAR wstr[]) {
114 int charCount = WideCharToMultiByte(
115 CP_UTF8, 0, wstr, -1,
nullptr, 0,
nullptr,
nullptr);
117 str.resize(charCount);
119 CP_UTF8, 0, wstr, -1, &str[0], charCount,
nullptr,
nullptr);
123 auto toWString = [](
const std::string &str) {
return str; };
124 auto toString = [](
const char *c) {
return std::string(c); };
127 WIN32_FIND_DATA FindFileData;
129 buffer = _getcwd(NULL, 0);
130 if((buffer = _getcwd(NULL, 0)) == NULL)
131 perror(
"_getcwd error");
137 = FindFirstFile(toWString(directoryName).c_str(), &FindFileData);
138 if(hFind == INVALID_HANDLE_VALUE) {
140 s =
"Could not open directory `";
147 const std::string filename = toString(FindFileData.cFileName);
149 std::string entryExtension(filename);
151 = entryExtension.substr(entryExtension.find_last_of(
'.') + 1);
153 if(entryExtension == extension)
154 filesInDir.push_back(filename);
155 std::string dir = directoryName;
156 dir.resize(dir.size() - 1);
157 while(FindNextFile(hFind, &FindFileData)) {
158 if(extension.size()) {
159 std::string entryExtension(filename);
161 = entryExtension.substr(entryExtension.find_last_of(
'.') + 1);
162 if(entryExtension == extension)
163 filesInDir.push_back(dir + filename);
165 if((filename !=
".") && (filename !=
"..")) {
166 filesInDir.push_back(directoryName +
"/" + filename);
173 DIR *d = opendir((directoryName +
"/").data());
176 msg =
"Could not open directory `";
177 msg += directoryName;
182 struct dirent *dirEntry;
183 while((dirEntry = readdir(d)) !=
nullptr) {
184 if(extension.size()) {
185 std::string entryExtension(dirEntry->d_name);
187 = entryExtension.substr(entryExtension.find_last_of(
'.') + 1);
188 if(entryExtension == extension)
189 filesInDir.push_back(directoryName +
"/"
190 + std::string(dirEntry->d_name));
192 if((std::string(dirEntry->d_name) !=
".")
193 && (std::string(dirEntry->d_name) !=
".."))
194 filesInDir.push_back(directoryName +
"/"
195 + std::string(dirEntry->d_name));
202 std::sort(filesInDir.begin(), filesInDir.end());