Read all files in a folder

Function function to read all files in the folder

void ReadPcdFlie(const std::string &InputPath, std::vector<string> &pcd_list){
    
    
      struct dirent *ptr;    
      DIR *dir;
      std::cout<< "ReadFlie()" << std::endl;
      dir=opendir(InputPath.c_str()); 
      // if((ptr=readdir(dir))=NULL){
    
    
      //   std::cout<< "Can't read the file!!!" << std::endl;
      // }

      if(dir==NULL){
    
    
        std::cout<< "Can't read the file!!!" << std::endl;
      }
      
      while((ptr=readdir(dir))!=NULL)
      {
    
    
          if(ptr->d_name[0] == '.')
              continue;
          std::string pcd_name = ptr->d_name;
          int point_index = pcd_name.find(".");
          std::string pcd_num = pcd_name.substr(0,point_index);//在"pcd_name"字符串中,从0位置开始截取point_index个字符
          pcd_list.push_back(pcd_num);
      }
      closedir(dir);
}

Guess you like

Origin blog.csdn.net/zhangqian_shai/article/details/129063017