summaryrefslogtreecommitdiffstats
path: root/source/OSSupport/File.cpp
diff options
context:
space:
mode:
authormadmaxoft <github@xoft.cz>2013-11-22 20:11:24 +0100
committermadmaxoft <github@xoft.cz>2013-11-22 20:11:24 +0100
commit63753c5e8405837931510b8da648dc75d4970fe1 (patch)
tree58e495519d269f4e6d7aff94294101a5911465cc /source/OSSupport/File.cpp
parentAPIDump: Fixed cRoot's furnace query API. (diff)
downloadcuberite-63753c5e8405837931510b8da648dc75d4970fe1.tar
cuberite-63753c5e8405837931510b8da648dc75d4970fe1.tar.gz
cuberite-63753c5e8405837931510b8da648dc75d4970fe1.tar.bz2
cuberite-63753c5e8405837931510b8da648dc75d4970fe1.tar.lz
cuberite-63753c5e8405837931510b8da648dc75d4970fe1.tar.xz
cuberite-63753c5e8405837931510b8da648dc75d4970fe1.tar.zst
cuberite-63753c5e8405837931510b8da648dc75d4970fe1.zip
Diffstat (limited to 'source/OSSupport/File.cpp')
-rw-r--r--source/OSSupport/File.cpp60
1 files changed, 60 insertions, 0 deletions
diff --git a/source/OSSupport/File.cpp b/source/OSSupport/File.cpp
index d2eea498a..86276bd79 100644
--- a/source/OSSupport/File.cpp
+++ b/source/OSSupport/File.cpp
@@ -360,6 +360,66 @@ bool cFile::CreateFolder(const AString & a_FolderPath)
+AStringVector cFile::GetFolderContents(const AString & a_Folder)
+{
+ AStringVector AllFiles;
+
+ #ifdef _WIN32
+
+ // If the folder name doesn't contain the terminating slash / backslash, add it:
+ AString FileFilter = a_Folder;
+ if (
+ !FileFilter.empty() &&
+ (FileFilter[FileFilter.length() - 1] != '\\') &&
+ (FileFilter[FileFilter.length() - 1] != '/')
+ )
+ {
+ FileFilter.push_back('\\');
+ }
+
+ // Find all files / folders:
+ FileFilter.append("*.*");
+ HANDLE hFind;
+ WIN32_FIND_DATA FindFileData;
+ if ((hFind = FindFirstFile(FileFilter.c_str(), &FindFileData)) != INVALID_HANDLE_VALUE)
+ {
+ do
+ {
+ AllFiles.push_back(FindFileData.cFileName);
+ } while (FindNextFile(hFind, &FindFileData));
+ FindClose(hFind);
+ }
+
+ #else // _WIN32
+
+ DIR * dp;
+ struct dirent *dirp;
+ if (*a_Directory == 0)
+ {
+ a_Directory = ".";
+ }
+ if ((dp = opendir(a_Directory)) == NULL)
+ {
+ LOGERROR("Error (%i) opening directory \"%s\"\n", errno, a_Directory );
+ }
+ else
+ {
+ while ((dirp = readdir(dp)) != NULL)
+ {
+ AllFiles.push_back(dirp->d_name);
+ }
+ closedir(dp);
+ }
+
+ #endif // else _WIN32
+
+ return AllFiles;
+}
+
+
+
+
+
int cFile::Printf(const char * a_Fmt, ...)
{
AString buf;