MCPcopy Create free account
hub / github.com/aardappel/treesheets / ScanDirAbs

Function ScanDirAbs

lobster/src/platform.cpp:358–398  ·  view source on GitHub ↗

TODO: can now replace all this platform specific stuff with std::filesystem code. https://github.com/tvaneerd/cpp17_in_TTs/blob/master/ALL_IN_ONE.md http://en.cppreference.com/w/cpp/experimental/fs

Source from the content-addressed store, hash-verified

356// https://github.com/tvaneerd/cpp17_in_TTs/blob/master/ALL_IN_ONE.md
357// http://en.cppreference.com/w/cpp/experimental/fs
358bool ScanDirAbs(string_view absdir, vector<pair<string, int64_t>> &dest) {
359 string folder = SanitizePath(absdir);
360 #ifdef _WIN32
361 WIN32_FIND_DATA fdata;
362 HANDLE fh = FindFirstFile((folder + "\\*.*").c_str(), &fdata);
363 if (fh != INVALID_HANDLE_VALUE) {
364 do {
365 if (strcmp(fdata.cFileName, ".") && strcmp(fdata.cFileName, "..")) {
366 ULONGLONG size =
367 (static_cast<ULONGLONG>(fdata.nFileSizeHigh) << (sizeof(uint) * 8)) |
368 fdata.nFileSizeLow;
369 dest.push_back(
370 { fdata.cFileName,
371 fdata.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY
372 ? -1
373 : (int64_t)size });
374 }
375 }
376 while(FindNextFile(fh, &fdata));
377 FindClose(fh);
378 return true;
379 }
380 #elif !defined(PLATFORM_ES3)
381 glob_t gl;
382 string mask = folder + "/*";
383 if (!glob(mask.c_str(), GLOB_MARK | GLOB_TILDE, nullptr, &gl)) {
384 for (size_t fi = 0; fi < gl.gl_pathc; fi++) {
385 string xFileName = gl.gl_pathv[fi];
386 bool isDir = xFileName[xFileName.length()-1] == '/';
387 if (isDir) xFileName = xFileName.substr(0, xFileName.length() - 1);
388 string cFileName = xFileName.substr(xFileName.find_last_of('/') + 1);
389 struct stat st;
390 stat(gl.gl_pathv[fi], &st);
391 dest.push_back({ cFileName, isDir ? -1 : (int64_t)st.st_size });
392 }
393 globfree(&gl);
394 return true;
395 }
396 #endif
397 return false;
398}
399
400bool ScanDir(string_view reldir, vector<pair<string, int64_t>> &dest) {
401 auto srfn = SanitizePath(reldir);

Callers 2

ScanDirFunction · 0.85
AddFileFunction · 0.85

Calls 4

SanitizePathFunction · 0.85
statClass · 0.85
lengthMethod · 0.80
c_strMethod · 0.45

Tested by

no test coverage detected