MCPcopy Create free account
hub / github.com/Beckhoff/ADS / Find

Method Find

AdsLib/AdsFile.cpp:86–126  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

84}
85
86int AdsFile::Find(const AdsDevice &route, const std::string &basePath,
87 const size_t maxdepth, std::ostream &os)
88{
89 struct Path {
90 size_t depth;
91 std::string path;
92 };
93 std::list<struct Path> pendingDirs{ { 0, basePath } };
94 while (!pendingDirs.empty()) {
95 auto path = pendingDirs.front().path;
96 auto depth = pendingDirs.front().depth;
97 pendingDirs.pop_front();
98
99 TcFileFindData parent;
100 if (FindFirst(route, parent, path)) {
101 return 1804;
102 }
103
104 // Path exists print it and prepare traversing
105 os << path << '\n';
106
107 if (parent.isDirectory() && (depth < maxdepth)) {
108 // Finding files in a directory is a bit weird. We get only one entry per call and for
109 // every call we pass the last found item to get the next. The first item is special.
110 // To get the children of a directory we have to append '/*'to the path of the directory.
111 for (auto last = FindFirst(route, parent, path + "/*");
112 !last; last = FindNext(route, parent)) {
113 if (parent.isDirectory()) {
114 pendingDirs.push_back(
115 { depth + 1,
116 path + '/' +
117 parent.cFileName });
118 } else {
119 os << path << '/' << parent.cFileName
120 << '\n';
121 }
122 }
123 }
124 }
125 return 0;
126}
127
128void AdsFile::Read(const size_t size, void *data, uint32_t &bytesRead) const
129{

Callers

nothing calls this directly

Calls 3

FindFirstFunction · 0.85
FindNextFunction · 0.85
isDirectoryMethod · 0.80

Tested by

no test coverage detected