MCPcopy Create free account
hub / github.com/OpenXcom/OpenXcom / getFolderContents

Function getFolderContents

src/Engine/CrossPlatform.cpp:498–545  ·  view source on GitHub ↗

* Gets the name of all the files * contained in a certain folder. * @param path Full path to folder. * @param ext Extension of files ("" if it doesn't matter). * @return Ordered list of all the files. */

Source from the content-addressed store, hash-verified

496 * @return Ordered list of all the files.
497 */
498std::vector<std::string> getFolderContents(const std::string &path, const std::string &ext)
499{
500 std::vector<std::string> files;
501 std::string extl = ext;
502 std::transform(extl.begin(), extl.end(), extl.begin(), ::tolower);
503
504 DIR *dp = opendir(path.c_str());
505 if (dp == 0)
506 {
507 #ifdef __MORPHOS__
508 return files;
509 #else
510 std::string errorMessage("Failed to open directory: " + path);
511 throw Exception(errorMessage);
512 #endif
513 }
514
515 struct dirent *dirp;
516 while ((dirp = readdir(dp)) != 0)
517 {
518 std::string file = dirp->d_name;
519
520 if (file == "." || file == "..")
521 {
522 continue;
523 }
524 if (!extl.empty())
525 {
526 if (file.length() >= extl.length() + 1)
527 {
528 std::string end = file.substr(file.length() - extl.length() - 1);
529 std::transform(end.begin(), end.end(), end.begin(), ::tolower);
530 if (end != "." + extl)
531 {
532 continue;
533 }
534 }
535 else
536 {
537 continue;
538 }
539 }
540
541 files.push_back(file);
542 }
543 closedir(dp);
544 return files;
545}
546
547/**
548 * Gets the name of all the files

Callers 8

getDataContentsFunction · 0.85
getListMethod · 0.85
getListMethod · 0.85
XcomResourcePackMethod · 0.85
RulesetMethod · 0.85
loadFilesMethod · 0.85
OptionsVideoStateMethod · 0.85

Calls 5

opendirFunction · 0.85
ExceptionClass · 0.85
readdirFunction · 0.85
closedirFunction · 0.85
emptyMethod · 0.45

Tested by

no test coverage detected