当前位置: 移动技术网 > IT编程>开发语言>C/C++ > C++ 获取文件下的所有文件的名字

C++ 获取文件下的所有文件的名字

2018年01月28日  | 移动技术网IT编程  | 我要评论

房价下跌最快城市,恩施人力资源和社会保障网,凌成兴的侄女

#include<iostream>
#include<opencv2\opencv.hpp>
#include<string>
#include<vector>

using namespace std;
using namespace cv;
void getFiles(string path, vector<string>& files)
{
    //文件句柄  
    long   hFile = 0;
    //文件信息  
    struct _finddata_t fileinfo;
    string p;
    if ((hFile = _findfirst(p.assign(path).append("\\*").c_str(), &fileinfo)) != -1)
    {
        do
        {
            //如果是目录,迭代之  
            //如果不是,加入列表  
            if ((fileinfo.attrib &  _A_SUBDIR))
            {
                if (strcmp(fileinfo.name, ".") != 0 && strcmp(fileinfo.name, "..") != 0)
                    getFiles(p.assign(path).append("\\").append(fileinfo.name), files);
            }
            else
            {
                files.push_back(p.assign(path).append("\\").append(fileinfo.name));
            }
        } while (_findnext(hFile, &fileinfo) == 0);
        _findclose(hFile);
    }
}

int main()
{
    string imgfile = "C:\\Users\\DP\\Desktop\\xiao-yolo\\Detector\\image";
    vector<string>filename;
    getFiles(imgfile, filename);
    for(int i=0;i<filename.size();i++){
        cout<<filename.at(i)<<endl;
    }
    return 0;
}

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网