C/C+获取文件夹下所有文件夹

代码:

#include <io.h>

std::vector<std::string> StoreActionServer::getFolderList(const std::string &path)
{
    std::vector<std::string> folderList;
    //文件句柄
    long   hFile   =   0;
    //文件信息
    _finddata_t fileinfo;
    std::string allPath; //文件或文件的完整路径
    if((hFile = _findfirst(allPath.assign(path).append("/*").c_str(),&fileinfo)) !=  -1){
        do{
            if((fileinfo.attrib &  _A_SUBDIR)){
                if(strcmp(fileinfo.name,".") != 0  &&  strcmp(fileinfo.name,"..") != 0){ //目录
                    std::string folderPath =  fileinfo.name;
                    folderList.push_back(folderPath);
                }else{//为文件
                }
            }
        }while(_findnext(hFile, &fileinfo)  == 0);
        _findclose(hFile);
    }
    zout << "folderList.size : "  << folderList.size();
    return folderList;
}

ps:在Linux里编译不通过




长风破浪会有时,直挂云帆济沧海!
可通过下方链接找到博主
https://www.cnblogs.com/judes/p/10875138.html
原文地址:https://www.cnblogs.com/judes/p/15065798.html