void GetFilesFromDirectory(std::vector<std::string> &files, const char *directoryPath) { struct _finddata_t fileinfo; long hFile = 0; char tmpPath[MAX_PATH] = { 0 }; sprintf_s(tmpPath, "%s\\*", directoryPath); if ((hFile = _findfirst(tmpPath, &fileinfo)) == -1){ return; } do { if ((fileinfo.attrib & _A_SUBDIR)) { if (strcmp(fileinfo.name, ".") != 0 && strcmp(fileinfo.name, "..") != 0) { sprintf_s(tmpPath, "%s\\%s", directoryPath, fileinfo.name); GetFilesFromDirectory(files, tmpPath); } } else { sprintf_s(tmpPath, "%s\\%s", directoryPath, fileinfo.name); files.push_back(tmpPath); } } while (_findnext(hFile, &fileinfo) == 0); _findclose(hFile); }
时间: 2024-10-13 01:07:34