+int GetFileList(std::vector<std::string> * fileList, const std::string & directory, mode_t mode, const std::string & ext)
+{
+DIR * d = opendir(directory.c_str());
+
+if (!d)
+ {
+ printfd(__FILE__, "GetFileList - Failed to open dir '%s': '%s'\n", directory.c_str(), strerror(errno));
+ return -1;
+ }
+
+dirent * entry;
+while ((entry = readdir(d)))
+ {
+ if (!(strcmp(entry->d_name, ".") && strcmp(entry->d_name, "..")))
+ continue;
+
+ std::string str = directory + "/" + std::string(entry->d_name);
+
+ struct stat st;
+ if (stat(str.c_str(), &st))
+ continue;
+
+ if (!(st.st_mode & mode)) // Filter by mode
+ continue;
+
+ if (!ext.empty())
+ {
+ // Check extension
+ size_t d_nameLen = strlen(entry->d_name);
+ if (d_nameLen <= ext.size())
+ continue;
+
+ if (ext == entry->d_name + (d_nameLen - ext.size()))
+ {
+ entry->d_name[d_nameLen - ext.size()] = 0;
+ fileList->push_back(entry->d_name);
+ }
+ }
+ else
+ {
+ fileList->push_back(entry->d_name);
+ }
+ }
+
+closedir(d);
+
+return 0;
+}
+//-----------------------------------------------------------------------------