Ubuntu遍历多级目录下文件
C++代码实现
C++ 遍历目录下所有文件
#include <dirent.h>
struct dirent *filename;
DIR *dir;
const char *p = path.c_str();
dir = opendir(p);
if (dir == NULL)
{
std::cerr << "can not open dir !" << std::endl;
}
while ((filename = readdir(dir)) != NULL)
{
if (strcmp(filename->d_name, ".") == 0|| strcmp(filename->d_name, "..") == 0)
{
continue;
}
std::cerr << "filename: " << filename->d_name << std::endl;
}
closedir(dir);