From ba5b6ca75187e18942c463f7300b49061ebdc183 Mon Sep 17 00:00:00 2001 From: "madmaxoft@gmail.com" Date: Sun, 25 Mar 2012 14:24:51 +0000 Subject: A globally-accessible OS-independent GetDirectoryContents() function for listing all objects in a folder as an AStringList git-svn-id: http://mc-server.googlecode.com/svn/trunk@433 0a769ca7-a7f5-676a-18bf-c427514a06d6 --- source/StringUtils.cpp | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) (limited to 'source/StringUtils.cpp') diff --git a/source/StringUtils.cpp b/source/StringUtils.cpp index c9dbb1113..1e629c25f 100644 --- a/source/StringUtils.cpp +++ b/source/StringUtils.cpp @@ -159,3 +159,47 @@ void ReplaceString(AString & iHayStack, const AString & iNeedle, const AString & +AStringList GetDirectoryContents(const char * a_Directory) +{ + AStringList AllFiles; + + #ifdef _WIN32 + + AString FileFilter = AString(a_Directory) + "*.*"; + 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 ((dp = opendir(a_Directory)) == NULL) + { + LOGERROR("Error (%i) opening %s\n", errno, a_Directory ); + } + else + { + while ((dirp = readdir(dp)) != NULL) + { + AllFiles.push_back(dirp->d_name); + } + closedir(dp); + } + + #endif // else _WIN32 + + return AllFiles; +} + + + + -- cgit v1.2.3