fix file finding

This commit is contained in:
Jacob Dufault 2017-03-05 23:19:00 -08:00
parent 36f69e61a9
commit 852a4218ba
3 changed files with 21 additions and 18 deletions

View File

@ -12,7 +12,7 @@
"**/.git": true, "**/.git": true,
"**/.svn": true, "**/.svn": true,
"**/.hg": true, "**/.hg": true,
"**/.DS_Store": true, "**/.DS_Store": true
"third_party/": true // "third_party/": true
} }
} }

View File

@ -613,8 +613,6 @@ int main(int argc, char** argv) {
_setmode(_fileno(stdin), O_BINARY); _setmode(_fileno(stdin), O_BINARY);
#endif #endif
IpcRegistry::instance()->Register<IpcMessage_Quit>(); IpcRegistry::instance()->Register<IpcMessage_Quit>();
IpcRegistry::instance()->Register<IpcMessage_IsAlive>(); IpcRegistry::instance()->Register<IpcMessage_IsAlive>();

View File

@ -1,11 +1,12 @@
#include "utils.h" #include "utils.h"
#include <cassert>
#include <iostream> #include <iostream>
#include <fstream> #include <fstream>
#include "tinydir.h" #include "tinydir.h"
std::vector<std::string> GetFilesInFolder(std::string folder, bool add_folder_to_path) { static std::vector<std::string> GetFilesInFolderHelper(std::string folder, std::string output_prefix) {
std::vector<std::string> result; std::vector<std::string> result;
tinydir_dir dir; tinydir_dir dir;
@ -21,21 +22,17 @@ std::vector<std::string> GetFilesInFolder(std::string folder, bool add_folder_to
goto bail; goto bail;
} }
std::string full_path; // Skip all dot files.
if (add_folder_to_path)
full_path = folder + "/";
full_path += file.name;
if (file.is_dir) {
// Ignore all dot directories.
// Note that we must always ignore the '.' and '..' directories, otherwise
// this will loop infinitely.
if (file.name[0] != '.') { if (file.name[0] != '.') {
for (std::string nested_file : GetFilesInFolder(full_path, true /*add_folder_to_path*/)) if (file.is_dir) {
// Note that we must always ignore the '.' and '..' directories, otherwise
// this will loop infinitely. The above check handles that for us.
for (std::string nested_file : GetFilesInFolderHelper(file.path, output_prefix + file.name + "/"))
result.push_back(nested_file); result.push_back(nested_file);
} }
}
else { else {
result.push_back(full_path); result.push_back(output_prefix + file.name);
}
} }
if (tinydir_next(&dir) == -1) { if (tinydir_next(&dir) == -1) {
@ -49,6 +46,14 @@ bail:
return result; return result;
} }
std::vector<std::string> GetFilesInFolder(std::string folder, bool add_folder_to_path) {
assert(folder.size() > 0);
if (folder[folder.size() - 1] != '/')
folder += '/';
return GetFilesInFolderHelper(folder, add_folder_to_path ? folder : "");
}
std::vector<std::string> ReadLines(std::string filename) { std::vector<std::string> ReadLines(std::string filename) {
std::vector<std::string> result; std::vector<std::string> result;