MCPcopy Create free account
hub / github.com/BohemiaInteractive/CWR / listFiles

Function listFiles

engine/Evaluator/Validate.cpp:21–62  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

19#endif
20
21static std::vector<std::string> listFiles(const std::string& dir, const std::string& ext)
22{
23 std::vector<std::string> files;
24#ifdef _WIN32
25 // Normalize slashes for Windows
26 std::string normDir = dir;
27 for (auto& c : normDir)
28 if (c == '/')
29 c = '\\';
30 // Remove trailing separator
31 while (!normDir.empty() && (normDir.back() == '\\' || normDir.back() == '/'))
32 normDir.pop_back();
33
34 WIN32_FIND_DATAA fd;
35 std::string pattern = normDir + "\\*" + ext;
36 HANDLE h = FindFirstFileA(pattern.c_str(), &fd);
37 if (h != INVALID_HANDLE_VALUE)
38 {
39 do
40 {
41 if (!(fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY))
42 files.push_back(normDir + "\\" + fd.cFileName);
43 } while (FindNextFileA(h, &fd));
44 FindClose(h);
45 }
46#else
47 DIR* d = opendir(dir.c_str());
48 if (d)
49 {
50 struct dirent* e;
51 while ((e = readdir(d)))
52 {
53 std::string name = e->d_name;
54 if (name.size() >= ext.size() && name.substr(name.size() - ext.size()) == ext)
55 files.push_back(dir + "/" + name);
56 }
57 closedir(d);
58 }
59#endif
60 std::sort(files.begin(), files.end());
61 return files;
62}
63
64static std::string readAll(const std::string& path)
65{

Callers 2

validateBookFunction · 0.85
validateRefFunction · 0.85

Calls 2

sizeMethod · 0.80
emptyMethod · 0.45

Tested by

no test coverage detected