std::vector<std::string> AtomPressInfo::getFilesFromPath(const char *path) {
std::vector<std::string> strFilesVec;
std::vector<std::string> strDirVec;
strDirVec.emplace_back(std::string(path));
DIR *dir = nullptr;
struct dirent *entry = nullptr;
for (int i = 0; i < strDirVec.size(); ++i) {
if ((dir = opendir(strDirVec[i].c_str())) == nullptr) {
continue;
}
while ((entry = readdir(dir)) != nullptr) {
if (entry->d_name[0] == '.') {
continue;
}
struct stat st{};
const char *p = entry->d_name;
std::string strAbsolutePath = strDirVec[i] + "/" + p;
const char *file = strAbsolutePath.c_str();
stat(file, &st);
if ((S_ISDIR(st.st_mode))) {
strDirVec.emplace_back(std::string(file));
} else {
strFilesVec.emplace_back(strAbsolutePath);
}
}
}
return strFilesVec;
}
C++获取给定目录下所有的文件
最新推荐文章于 2022-12-14 16:57:51 发布