前言
由于项目中需要读取某个文件夹的所有文件路径,这里简单总结如下,仅供备忘。
一 代码 1.1 头文件include/algorithm.h
#include#include#includeusing namespace std; #define linux //#define _WIN32 vectorgetFilesList(string dirpath); vectorgetFilesList(string dir);1.2 cpp
src/algorithm.cpp
#include "algorithm.h" #ifdef linux #include #include vectorgetFilesList(string dirpath) { vectorallPath; DIR *dir = opendir(dirpath.c_str()); if (dir == NULL) { cout << "opendir error" << endl; return allPath; } struct dirent *entry; while ((entry = readdir(dir)) != NULL) { if (entry->d_type == DT_DIR) {//It's dir if (strcmp(entry->d_nam