diff options
author | madmaxoft <github@xoft.cz> | 2013-11-22 20:11:24 +0100 |
---|---|---|
committer | madmaxoft <github@xoft.cz> | 2013-11-22 20:11:24 +0100 |
commit | 63753c5e8405837931510b8da648dc75d4970fe1 (patch) | |
tree | 58e495519d269f4e6d7aff94294101a5911465cc /source/OSSupport | |
parent | APIDump: Fixed cRoot's furnace query API. (diff) | |
download | cuberite-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')
-rw-r--r-- | source/OSSupport/File.cpp | 60 | ||||
-rw-r--r-- | source/OSSupport/File.h | 3 |
2 files changed, 63 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; diff --git a/source/OSSupport/File.h b/source/OSSupport/File.h index cfb3a2019..70f81c8d2 100644 --- a/source/OSSupport/File.h +++ b/source/OSSupport/File.h @@ -123,6 +123,9 @@ public: // tolua_end + /// Returns the list of all items in the specified folder (files, folders, nix pipes, whatever's there). + static AStringVector GetFolderContents(const AString & a_Folder); // Exported in ManualBindings.cpp + int Printf(const char * a_Fmt, ...); private: |