#include #include #include #include void ScanDirectoryForExtension ( std::vector &outPaths, const char *path, const char *ending, bool recursive ) { DIR *dir = opendir(path); if (!dir) { return; } size_t endingLen = strlen(ending); dirent *ent; while ((ent = readdir(dir))) { if (strcmp(ent->d_name, ".") == 0 || strcmp(ent->d_name, "..") == 0) continue; else if (recursive && ent->d_type == DT_DIR) { std::string tmpPath(path); tmpPath.append("/"); tmpPath.append(ent->d_name); ScanDirectoryForExtension( outPaths, tmpPath.c_str(), ending, recursive ); } else { size_t nameLen = strlen(ent->d_name); if (endingLen <= nameLen && memcmp ( ent->d_name + nameLen - endingLen, ending, endingLen ) == 0 ) { std::string tmpPath(path); tmpPath.append("/"); tmpPath.append(ent->d_name); outPaths.push_back(std::move(tmpPath)); } } } closedir(dir); }