MCPcopy Create free account
hub / github.com/REGoth-project/REGoth / forEachFile

Method forEachFile

src/utils/Utils.cpp:42–72  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

40}
41
42void ::Utils::forEachFile(const std::string& directory, std::function<void(const std::string&, const std::string&, const std::string&)> fn, bool recursive)
43{
44 tinydir_dir dir;
45 if (tinydir_open(&dir, directory.c_str()) == -1)
46 {
47 LogError() << "Failed to open directory: " << directory;
48 tinydir_close(&dir);
49 return;
50 }
51
52 while (dir.has_next)
53 {
54 tinydir_file file;
55 if (tinydir_readfile(&dir, &file) == -1)
56 {
57 LogError() << "Error getting file";
58 tinydir_close(&dir);
59 return;
60 }
61
62 // Recurse, if this is a directory and we want recursion
63 if (recursive && file.is_dir && std::string(file.name) != ".." && std::string(file.name) != ".")
64 forEachFile(directory + "/" + file.name, fn, true);
65 else // If not a directory, call the users function
66 fn(file.path, file.name, file.extension);
67
68 tinydir_next(&dir);
69 }
70
71 tinydir_close(&dir);
72}
73
74std::list<std::string> Utils::getFilesInDirectory(const std::string& directory, const std::string& ext, bool recursive)
75{

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected