1. 关键是#include <dirent.h>头文件中包含的一些关于文件操作的属性。可以将文件夹及子文件夹中的文件信息提取出来保存在vector<string>中
/*
环境: LInux
*/
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <dirent.h>
#include <string.h>
#include <iostream>
#include <time.h>
#include <vector>
#include <algorithm>
using namespace std;
//文件夹下文件信息及其子文件夹中的文件信息
void listDir(const char *name, vector<string> &fileNames, bool lastSlash);
int main()
{
string directoryPath="/root/testDir/";
vector<string> fileNames;
listDir(directoryPath.c_str(),fileNames,true);
cout<<"total files: "<<fileNames.size()<<endl;
cout<<fileNames[0]<<endl;
return 0;
}
void listDir(const char *name, vector<string> &fileNames, bool lastSlash)
{
DIR *dir;
struct dirent *entry;
struct stat statbuf;
struct tm *tm;
ti