MCPcopy Create free account
hub / github.com/BZFlag-Dev/bzflag / WindowsAddFileStack

Function WindowsAddFileStack

plugins/plugin_utils/plugin_files.cpp:29–101  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

27#include <direct.h>
28
29bool WindowsAddFileStack(const char* szPathName, const char* fileMask,
30 bool bRecursive, std::vector<std::string> &list,
31 bool justDirs = false) {
32 struct _finddata_t fileInfo;
33
34 long hFile;
35 std::string searchstr;
36
37 std::string FilePath;
38
39 bool bDone = false;
40
41 searchstr = szPathName;
42 searchstr += "\\";
43 if (bRecursive) {
44 searchstr += "*.*";
45 }
46 else if (fileMask) {
47 searchstr += fileMask;
48 }
49 else {
50 searchstr += "*.*";
51 }
52
53 std::string extenstionSearch;
54
55 if (fileMask && strchr(fileMask, '.')) {
56 extenstionSearch = strchr(fileMask, '.') + 1;
57 }
58
59 hFile = (long)_findfirst(searchstr.c_str(), &fileInfo);
60
61 if (hFile != -1) {
62 while (!bDone) {
63 if ((strlen(fileInfo.name) > 0) && (strcmp(fileInfo.name, ".") != 0) &&
64 (strcmp(fileInfo.name, "..") != 0)) {
65 FilePath = szPathName;
66 //if (!(fileInfo.attrib & _A_SUBDIR))
67 FilePath += "\\";
68 FilePath += fileInfo.name;
69
70 if (justDirs && (fileInfo.attrib & _A_SUBDIR)) {
71 // we neever do just dirs recrusively
72 list.push_back(FilePath);
73 }
74 else if (!justDirs) {
75 if ((fileInfo.attrib & _A_SUBDIR) && bRecursive) {
76 WindowsAddFileStack(FilePath.c_str(), fileMask, bRecursive, list);
77 }
78 else if (!(fileInfo.attrib & _A_SUBDIR)) {
79 if (bRecursive && fileMask) {
80 // if we are recusive we need to check extension manualy,
81 // so we get dirs and stuff
82 if (strrchr(FilePath.c_str(), '.')) {
83 if (compare_nocase(std::string(strrchr(FilePath.c_str(), '.') + 1),
84 extenstionSearch) == 0) {
85 list.push_back(FilePath);
86 }

Callers 2

getFilesInDirFunction · 0.85
getDirsInDirFunction · 0.85

Calls 3

c_strMethod · 0.80
compare_nocaseFunction · 0.70
push_backMethod · 0.45

Tested by

no test coverage detected