MCPcopy Create free account
hub / github.com/FlaxEngine/FlaxEngine / GetChildDirectories

Method GetChildDirectories

Source/Engine/Platform/Unix/UnixFileSystem.cpp:164–225  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

162}
163
164bool UnixFileSystem::GetChildDirectories(Array<String>& results, const String& path)
165{
166#if HAS_DIRS
167 size_t pathLength;
168 DIR* dir;
169 struct stat statPath, statEntry;
170 struct dirent* entry;
171 const UnixString pathANSI(*path, path.Length());
172 const char* pathStr = pathANSI.Get();
173
174 // Stat for the path
175 stat(pathStr, &statPath);
176
177 // If path does not exists or is not dir - exit with status -1
178 if (S_ISDIR(statPath.st_mode) == 0)
179 {
180 // Is not directory
181 return true;
182 }
183
184 // If not possible to read the directory for this user
185 if ((dir = opendir(pathStr)) == NULL)
186 {
187 // Cannot open directory
188 return true;
189 }
190
191 // The length of the path
192 pathLength = strlen(pathStr);
193
194 // Iteration through entries in the directory
195 while ((entry = readdir(dir)) != NULL)
196 {
197 // Skip entries "." and ".."
198 if (!strcmp(entry->d_name, ".") || !strcmp(entry->d_name, ".."))
199 continue;
200
201 // Determinate a full path of an entry
202 char fullPath[256];
203 ASSERT(pathLength + strlen(entry->d_name) < ARRAY_COUNT(fullPath));
204 strcpy(fullPath, pathStr);
205 strcat(fullPath, "/");
206 strcat(fullPath, entry->d_name);
207
208 // Stat for the entry
209 stat(fullPath, &statEntry);
210
211 // Check for directory
212 if (S_ISDIR(statEntry.st_mode) != 0)
213 {
214 // Add directory
215 results.Add(String(fullPath));
216 }
217 }
218
219 closedir(dir);
220
221 return false;

Callers

nothing calls this directly

Calls 5

statClass · 0.70
StringClass · 0.50
LengthMethod · 0.45
GetMethod · 0.45
AddMethod · 0.45

Tested by

no test coverage detected