1
0

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
This commit is contained in:
madmaxoft@gmail.com
2012-03-25 14:24:51 +00:00
parent 534e221316
commit ba5b6ca751
6 changed files with 81 additions and 85 deletions

View File

@@ -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;
}