How do I get a list of files in a directory in C++?

后端 未结 13 1454
南旧
南旧 2020-11-28 23:36

How do you get a list of files within a directory so each can be processed?

13条回答
  •  旧巷少年郎
    2020-11-28 23:59

    void getFilesList(String filePath,String extension, vector & returnFileName)
    {
        WIN32_FIND_DATA fileInfo;
        HANDLE hFind;   
        String  fullPath = filePath + extension;
        hFind = FindFirstFile(fullPath.c_str(), &fileInfo);
        if (hFind == INVALID_HANDLE_VALUE){return;} 
        else {
            return FileName.push_back(filePath+fileInfo.cFileName);
            while (FindNextFile(hFind, &fileInfo) != 0){
                return FileName.push_back(filePath+fileInfo.cFileName);}
            }
     }
    
    
     String optfileName ="";        
     String inputFolderPath =""; 
     String extension = "*.jpg*";
     getFilesList(inputFolderPath,extension,filesPaths);
     vector::const_iterator it = filesPaths.begin();
     while( it != filesPaths.end())
     {
        frame = imread(*it);//read file names
                //doyourwork here ( frame );
        sprintf(buf, "%s/Out/%d.jpg", optfileName.c_str(),it->c_str());
        imwrite(buf,frame);   
        it++;
     }
    

提交回复
热议问题