Fix dir iteration on Windows

Instead of passing the directory to FindFirstFile(), a wildcard
of the form C:\Path\To\Dir\* needs to be passed.
This commit is contained in:
Robert Knight 2011-08-22 18:28:42 +01:00
parent 66dc8d4720
commit 57e13d941b
2 changed files with 20 additions and 1 deletions

View File

@ -1,9 +1,18 @@
#include "Dir.h"
#include "Log.h"
#include "StringUtils.h"
#ifdef PLATFORM_UNIX
#include <dirent.h>
#endif
bool endsWith(const std::string& str, const char* text)
{
int length = strlen(text);
return str.find(text,str.size() - length) != 0;
}
Dir::Dir(const char* path)
{
m_path = path;
@ -11,7 +20,16 @@ Dir::Dir(const char* path)
#ifdef PLATFORM_UNIX
m_dir = opendir(path);
#else
m_findHandle = FindFirstFile(path,&m_findData);
// to list the contents of a directory, the first
// argument to FindFirstFile needs to be a wildcard
// of the form: C:\path\to\dir\*
std::string searchPath = m_path;
if (!endsWith(searchPath,"/"))
{
searchPath.append("/");
}
searchPath.append("*");
m_findHandle = FindFirstFile(searchPath.c_str(),&m_findData);
m_firstEntry = true;
#endif
}

View File

@ -1,6 +1,7 @@
#include "FileOps.h"
#include "Dir.h"
#include "Log.h"
#include "Platform.h"
#include "StringUtils.h"