MCPcopy Create free account
hub / github.com/assaultcube/AC / listsubdir

Function listsubdir

source/src/stream.cpp:295–335  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

293#endif
294
295bool listsubdir(const char *dir, vector<char *> &subdirs)
296{
297 #if defined(WIN32)
298 defformatstring(pathname)("%s\\*", dir);
299 WIN32_FIND_DATA FindFileData;
300 HANDLE Find = FindFirstFile(path(pathname), &FindFileData);
301 if(Find != INVALID_HANDLE_VALUE)
302 {
303 do {
304 if((FindFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) && FindFileData.cFileName[0] != '.') subdirs.add(newstring(FindFileData.cFileName));
305 } while(FindNextFile(Find, &FindFileData));
306 FindClose(Find);
307 return true;
308 }
309 #else
310 string pathname;
311 copystring(pathname, dir);
312 DIR *d = opendir(path(pathname));
313 if(d)
314 {
315 struct dirent *de, b;
316 while(!readdir_r_(d, &b, &de) && de != NULL)
317 {
318 #ifdef _DIRENT_HAVE_D_TYPE
319 if(de->d_type == DT_DIR && de->d_name[0] != '.') subdirs.add(newstring(de->d_name));
320 else if(de->d_type == DT_UNKNOWN && de->d_name[0] != '.')
321 #endif
322 {
323 struct stat s;
324 int dl = (int)strlen(pathname);
325 concatformatstring(pathname, "/%s", de->d_name);
326 if(!lstat(pathname, &s) && S_ISDIR(s.st_mode) && de->d_name[0] != '.') subdirs.add(newstring(de->d_name));
327 pathname[dl] = '\0';
328 }
329 }
330 closedir(d);
331 return true;
332 }
333 #endif
334 else return false;
335}
336
337void listsubdirs(const char *dir, vector<char *> &subdirs, int (__cdecl *sf)(const char **, const char **))
338{

Callers 2

listsubdirsFunction · 0.85
loopvFunction · 0.85

Calls 6

pathFunction · 0.85
newstringFunction · 0.85
copystringFunction · 0.85
readdir_r_Function · 0.85
concatformatstringFunction · 0.85
addMethod · 0.45

Tested by

no test coverage detected