Unified SystemToolkit list directory with dialog file patterns

This commit is contained in:
Bruno Herbelin
2021-12-05 18:39:58 +01:00
parent e5334aae0a
commit 923d84f378
3 changed files with 10 additions and 7 deletions

View File

@@ -43,6 +43,7 @@ using namespace std;
#include <sys/stat.h>
#include <pwd.h>
#include <dirent.h>
#include <fnmatch.h>
#define PATH_SEP '/'
#endif
@@ -298,7 +299,7 @@ std::string SystemToolkit::path_directory(const std::string& path)
return directorypath;
}
list<string> SystemToolkit::list_directory(const string& path, const list<string>& extensions)
list<string> SystemToolkit::list_directory(const string& path, const list<string>& patterns)
{
list<string> ls;
@@ -309,10 +310,12 @@ list<string> SystemToolkit::list_directory(const string& path, const list<string
while ((ent = readdir (dir)) != NULL) {
if ( ent->d_type == DT_REG)
{
string filename = string(ent->d_name);
string ext = extension_filename(filename);
if ( extensions.empty() || find(extensions.cbegin(), extensions.cend(), ext) != extensions.cend())
ls.push_back( full_filename(path, filename) );
int found = FNM_NOMATCH;
for (auto it = patterns.cbegin(); it != patterns.cend() && found == FNM_NOMATCH; ++it)
// test pattern in CASE insensitive
found = fnmatch( it->c_str(), ent->d_name, FNM_CASEFOLD );
if (found != FNM_NOMATCH)
ls.push_back( full_filename(path, ent->d_name) );
}
}
closedir (dir);