31 lines
812 B
C++
31 lines
812 B
C++
#pragma once
|
|
|
|
#include <dirent.h>
|
|
#include <cstring>
|
|
#include <fstream>
|
|
#include <sstream>
|
|
#include <string>
|
|
#include <unordered_map>
|
|
#include <vector>
|
|
|
|
static inline int read_files_in_dir(const char* p_dir_name, std::vector<std::string>& file_names) {
|
|
DIR* p_dir = opendir(p_dir_name);
|
|
if (p_dir == nullptr) {
|
|
return -1;
|
|
}
|
|
|
|
struct dirent* p_file = nullptr;
|
|
while ((p_file = readdir(p_dir)) != nullptr) {
|
|
if (strcmp(p_file->d_name, ".") != 0 && strcmp(p_file->d_name, "..") != 0) {
|
|
//std::string cur_file_name(p_dir_name);
|
|
//cur_file_name += "/";
|
|
//cur_file_name += p_file->d_name;
|
|
std::string cur_file_name(p_file->d_name);
|
|
file_names.push_back(cur_file_name);
|
|
}
|
|
}
|
|
|
|
closedir(p_dir);
|
|
return 0;
|
|
}
|