diff options
author | Tiger Wang <ziwei.tiger@hotmail.co.uk> | 2013-11-24 15:55:08 +0100 |
---|---|---|
committer | Tiger Wang <ziwei.tiger@hotmail.co.uk> | 2013-11-24 15:55:08 +0100 |
commit | f95064a85c83e1a77a5de2f8a09e5907573f8277 (patch) | |
tree | 9896aa6cff228acbc0b188b6c37e2032152fe661 /source/OSSupport/File.cpp | |
parent | Fixed some comments and added debug logging (diff) | |
parent | RCONClient: Initial implementation. (diff) | |
download | cuberite-f95064a85c83e1a77a5de2f8a09e5907573f8277.tar cuberite-f95064a85c83e1a77a5de2f8a09e5907573f8277.tar.gz cuberite-f95064a85c83e1a77a5de2f8a09e5907573f8277.tar.bz2 cuberite-f95064a85c83e1a77a5de2f8a09e5907573f8277.tar.lz cuberite-f95064a85c83e1a77a5de2f8a09e5907573f8277.tar.xz cuberite-f95064a85c83e1a77a5de2f8a09e5907573f8277.tar.zst cuberite-f95064a85c83e1a77a5de2f8a09e5907573f8277.zip |
Diffstat (limited to 'source/OSSupport/File.cpp')
-rw-r--r-- | source/OSSupport/File.cpp | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/source/OSSupport/File.cpp b/source/OSSupport/File.cpp index d2eea498a..274aa52da 100644 --- a/source/OSSupport/File.cpp +++ b/source/OSSupport/File.cpp @@ -360,6 +360,82 @@ 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; +} + + + + + +AString cFile::ReadWholeFile(const AString & a_FileName) +{ + cFile f; + if (!f.Open(a_FileName, fmRead)) + { + return ""; + } + AString Contents; + f.ReadRestOfFile(Contents); + return Contents; +} + + + + + int cFile::Printf(const char * a_Fmt, ...) { AString buf; |