aboutsummaryrefslogtreecommitdiffstats
path: root/src/fileutils.cpp
diff options
context:
space:
mode:
authorGravatar Peter Powell2019-06-10 13:40:37 +0100
committerGravatar Peter Powell2019-06-10 13:40:37 +0100
commit6e898936d6e0f44da0992ad09139f0e8e6d141af (patch)
tree21f9d47e49b62fb53e472143eb2907bbd8b990f7 /src/fileutils.cpp
parentAdd a way to disable older SSL versions with ssl_openssl. (diff)
downloadinspircd++-6e898936d6e0f44da0992ad09139f0e8e6d141af.tar.gz
inspircd++-6e898936d6e0f44da0992ad09139f0e8e6d141af.tar.bz2
inspircd++-6e898936d6e0f44da0992ad09139f0e8e6d141af.zip
Add a method for getting a list of files in a directory.
Diffstat (limited to 'src/fileutils.cpp')
-rw-r--r--src/fileutils.cpp34
1 files changed, 34 insertions, 0 deletions
diff --git a/src/fileutils.cpp b/src/fileutils.cpp
index 731e4ea01..d5e1e5839 100644
--- a/src/fileutils.cpp
+++ b/src/fileutils.cpp
@@ -86,6 +86,40 @@ bool FileSystem::FileExists(const std::string& file)
return !access(file.c_str(), F_OK);
}
+bool FileSystem::GetFileList(const std::string& directory, std::vector<std::string>& entries, const std::string& match)
+{
+#ifdef _WIN32
+ const std::string search_path = directory + "\\" + match;
+
+ WIN32_FIND_DATAA wfd;
+ HANDLE fh = FindFirstFileA(search_path.c_str(), &wfd);
+ if (fh == INVALID_HANDLE_VALUE)
+ return false;
+
+ do
+ {
+ entries.push_back(wfd.cFileName);
+ } while (FindNextFile(fh, &wfd) != 0);
+
+ FindClose(fh);
+ return true;
+#else
+ DIR* library = opendir(directory.c_str());
+ if (!library)
+ return false;
+
+ dirent* entry = NULL;
+ while ((entry = readdir(library)))
+ {
+ if (InspIRCd::Match(entry->d_name, match, ascii_case_insensitive_map))
+ entries.push_back(entry->d_name);
+ }
+ closedir(library);
+ return true;
+#endif
+}
+
+
std::string FileSystem::GetFileName(const std::string& name)
{
#ifdef _WIN32