1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
| int FileHelper::os_bit() { return sizeof(int*) * 8; }
bool FileHelper::readFileNamesFromDir(const std::string& dirPath, std::vector<std::string>& imgNames, const std::string& fileFilters) { if (FileHelper::os_bit() == 64) { __finddata64_t fileinfo; __int64 hFile = 0; if ((hFile = _findfirst64((dirPath + "/*").c_str(), &fileinfo)) != -1) { do { if (fileinfo.attrib == 32) { std::regex img_reg(fileFilters); std::smatch img_res; std::string tmpFileName = std::string(fileinfo.name); std::transform(tmpFileName.begin(), tmpFileName.end(), tmpFileName.begin(), ::tolower); if (regex_search(tmpFileName, img_res, img_reg)) { imgNames.push_back(fileinfo.name); } } } while (_findnext64(hFile, &fileinfo) == 0); _findclose(hFile); } else return false; } else { _finddata32_t fileinfo; __int32 hFile = 0; if ((hFile = static_cast<__int32>(_findfirst32((dirPath + "/*").c_str(), &fileinfo)) != -1)) { do { if (fileinfo.attrib == 32) { std::regex img_reg(fileFilters); std::smatch img_res; std::string tmpFileName = std::string(fileinfo.name); std::transform(tmpFileName.begin(), tmpFileName.end(), tmpFileName.begin(), ::tolower); if (regex_search(tmpFileName, img_res, img_reg)) { imgNames.push_back(fileinfo.name); } } } while (_findnext32(hFile, &fileinfo) == 0); _findclose(hFile); } else return false; } return true; }
|