* 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. */
| 496 | * @return Ordered list of all the files. |
| 497 | */ |
| 498 | std::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 |
no test coverage detected