C++读取当前路径下所有文件

    CFileDialog dialog(TRUE, "image", "*.png", OFN_NOCHANGEDIR | OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,
        _T(".data(*.png)|*.png||"), NULL);
    if (dialog.DoModal() != IDOK)
        return;
    string path_in = dialog.GetPathName();
    int pos = path_in.find_last_of('\\');
    string path_file = path_in.substr(0, pos);

    vector<string> path_image; //完整的图片路径
    vector<string> name_image; //图片的名字

    //文件句柄  
     long   hFile = 0;
     //文件信息  
     struct _finddata_t fileinfo;
     string p;
     if ((hFile = _findfirst(p.assign(path_file).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, ownname ); */
             }
             else
             {
                 path_image.push_back(p.assign(path_file).append("\\").append(fileinfo.name));
                 name_image.push_back(fileinfo.name);
             }
         }while (_findnext(hFile, &fileinfo) == 0);
         _findclose(hFile);
     }

猜你喜欢

转载自blog.csdn.net/Xu_Haocan/article/details/80506681