Dir iterator implementation for Win32 - Untested

This commit is contained in:
Robert Knight 2011-08-22 15:50:15 +01:00
parent 28b9d50f0a
commit f4c6f1c1d7
2 changed files with 38 additions and 1 deletions

View file

@ -5,26 +5,53 @@
#endif
Dir::Dir(const char* path)
: m_dir(0)
{
m_path = path;
#ifdef PLATFORM_UNIX
m_dir = opendir(path);
#else
m_findHandle = FindFirstFile(path,&m_findData);
m_firstEntry = true;
#endif
}
Dir::~Dir()
{
#ifdef PLATFORM_UNIX
closedir(m_dir);
#else
FindClose(m_findHandle);
#endif
}
bool Dir::next()
{
#ifdef PLATFORM_UNIX
m_entry = readdir(m_dir);
return m_entry != 0;
#else
bool result;
if (m_firstEntry)
{
m_firstEntry = false;
return m_findHandle != INVALID_HANDLE_VALUE;
}
else
{
result = FindNextFile(m_findHandle,&m_findData);
}
return result;
#endif
}
std::string Dir::fileName() const
{
#ifdef PLATFORM_UNIX
return m_entry->d_name;
#else
return m_findData.cFileName;
#endif
}
std::string Dir::filePath() const
@ -34,6 +61,10 @@ std::string Dir::filePath() const
bool Dir::isDir() const
{
#ifdef PLATFORM_UNIX
return m_entry->d_type == DT_DIR;
#else
return (m_findData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0;
#endif
}

View file

@ -30,5 +30,11 @@ class Dir
DIR* m_dir;
dirent* m_entry;
#endif
#ifdef PLATFORM_WINDOWS
HANDLE m_findHandle;
WIN32_FIND_DATA m_findData;
bool m_firstEntry;
#endif
};