Linux 获取文件夹下的所有文件

时间:2021-11-12 03:25:52

作者:jostree 转载请注明出处 http://www.cnblogs.com/jostree/p/4129616.html

 #include <string>
#include <fstream>
#include <iostream>
#include <stdlib.h>
#include <dirent.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <string.h>
using namespace std;
void List(const char *path, int level, vector<string> &strvec) \
{
struct dirent* ent = NULL;
DIR *pDir;
pDir = opendir(path);
if (pDir == NULL)
{
return;
}
while (NULL != (ent = readdir(pDir)))
{
if (ent->d_type == )
{
//file
strvec.push_back(ent->d_name);
}
else
{
if (strcmp(ent->d_name, ".") == || strcmp(ent->d_name, "..") == )
{
continue;
}
//directory
string _path(path);
string _dirName(ent->d_name);
string fullDirPath = _path + "/" + _dirName;
List(fullDirPath.c_str(), level + , strvec);
}
}
}