void Enum_Folder(const string& strFolder, vector<string*>& vFileList)
{
DIR* dirptr = opendir(strFolder.c_str());
if(dirptr){
while(true){
struct dirent *entry = readdir(dirptr);
if(entry){
if(strcmp(entry->d_name, ".") == 0 || strcmp(entry->d_name, "..") == 0){
continue;
}
if(entry->d_type & DT_DIR){
char cModule[2048] = {0};
sprintf(cModule, "%s/%s", strFolder.c_str(), entry->d_name);
Enum_Folder(cModule, vFileList);
}
else{
string* pPath = NULL;
while(!pPath){
try{
pPath = new string;
}
catch(...){}
}
*pPath = strFolder;
*pPath += "/";
*pPath += entry->d_name;
vFileList.push_back(pPath);
}
}
else{
break;
}
}
closedir(dirptr);
}
}
需要在函数外释放资源
Centos7 遍历目录
最新推荐文章于 2022-03-02 11:45:35 发布