#include <stdio.h>
#include <dirent.h>
#include <queue>
#include <vector>
#include <string>
#include <iostream>
using namespace std;
int main() {
struct dirent *dirp;
vector<string>ve;
queue<string>q;
string targetPath="./";
q.push(targetPath);
while(!q.empty()){
string tempTargetPath=q.front();q.pop();
printf("%s\n", tempTargetPath.data());
DIR* dir = opendir(tempTargetPath.data());
while ((dirp = readdir(dir)) != NULL) {
if (dirp->d_type == DT_REG) {
// 文件
ve.push_back(tempTargetPath+dirp->d_name);
// printf("%s\n", dirp->d_name);
} else if (dirp->d_type == DT_DIR) {
// 文件夹
if((dirp->d_name[0]>='0'&&dirp->d_name[0]<='9')||(dirp->d_name[0]>='a'&&dirp->d_name[0]<='z')||(dirp->d_name[0]>='A'&&dirp->d_name[0]<='Z'))
q.push(tempTargetPath+dirp->d_name+'/');
// printf("%s\n", dirp->d_name);
}
}
closedir(dir);
cout<<q.size()<<endl;
}
for(int i=0;i<ve.size();i++){
cout<<ve[i]<<endl;
}
return 0;
}
MAC中使用C++读取某文件夹中的所有文件
最新推荐文章于 2023-08-02 21:00:08 发布