函数功能,实现读取文件夹下的所有文件
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);
}
该函数ReadPcdFile用于读取指定路径InputPath下的所有非隐藏Pcd文件,将文件名存储到pcd_list向量中。首先打开目录,然后通过readdir循环遍历文件,遇到以.开头的隐藏文件则跳过,否则提取出不包含扩展名的文件名并添加到列表中。

被折叠的 条评论
为什么被折叠?



