C++解析文件夹中的文件
发布时间
阅读量:
阅读量
以下提供了一种较为简单的实现方式,用于获取文件夹内所有子文件夹及文件的信息,若需访问子文件夹中的全部文件内容,可采用递归处理的方法。
#include <dirent.h>
#include <stdio.h>
#include <string.h>
void read_dir(std::string fileDir, std::vector<std::string>& files)
{
struct dirent *ent = NULL;
DIR *dir = opendir(fileDir.c_str());
if (dir != NULL)
{
while ((ent = readdir(dir)) != NULL)
{
if (strcmp(ent->d_name, ".") != 0 && strcmp(ent->d_name, "..") != 0)
{
//std::cout << ent->d_name << std::endl;
files.push_back(ent->d_name);
}
}
全部评论 (0)
还没有任何评论哟~
