diff options
author | Andrei Karas <akaras@inbox.ru> | 2016-01-25 18:40:05 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2016-01-25 18:40:05 +0300 |
commit | 2157b8c6629cea79801566244fc3f1d8491e91be (patch) | |
tree | fb999e7d464c70511f13472da0fba86749b8d737 /src/utils | |
parent | e89fb908638196c9484a2038e3f3eb18db6ef4ee (diff) | |
download | manaplus-2157b8c6629cea79801566244fc3f1d8491e91be.tar.gz manaplus-2157b8c6629cea79801566244fc3f1d8491e91be.tar.bz2 manaplus-2157b8c6629cea79801566244fc3f1d8491e91be.tar.xz manaplus-2157b8c6629cea79801566244fc3f1d8491e91be.zip |
Add file utils function getFilesInDir.
Diffstat (limited to 'src/utils')
-rw-r--r-- | src/utils/files.cpp | 18 | ||||
-rw-r--r-- | src/utils/files.h | 5 |
2 files changed, 23 insertions, 0 deletions
diff --git a/src/utils/files.cpp b/src/utils/files.cpp index e694a2b9e..0a3f3eb92 100644 --- a/src/utils/files.cpp +++ b/src/utils/files.cpp @@ -31,7 +31,9 @@ #include "utils/mkdir.h" #include "utils/paths.h" #include "utils/physfstools.h" +#include "utils/stringutils.h" +#include <algorithm> #include <dirent.h> #include <fstream> #include <sstream> @@ -363,3 +365,19 @@ void Files::deleteFilesInDirectory(std::string path) if (dir) closedir(dir); } + +void Files::getFilesInDir(const std::string &dir, + StringVect &list, + const std::string &ext) +{ + const std::string path = dir + "/"; + StringVect tempList; + Files::getFilesWithDir(path, tempList); + FOR_EACH (StringVectCIter, it, tempList) + { + const std::string &str = *it; + if (findLast(str, ext)) + list.push_back(str); + } + std::sort(list.begin(), list.end()); +} diff --git a/src/utils/files.h b/src/utils/files.h index 80ecb9a43..8123a5949 100644 --- a/src/utils/files.h +++ b/src/utils/files.h @@ -77,6 +77,11 @@ namespace Files const std::string &restrict text); void deleteFilesInDirectory(std::string path); + + void getFilesInDir(const std::string &dir, + StringVect &list, + const std::string &ext); + } // namespace Files #endif // UTILS_FILES_H |