4
Fork 0
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

45 lines
1.0 KiB

#include "IDirectoryIterator.h"
#include <string>
IDirectoryIterator::IDirectoryIterator(const char * path, const char * match)
:m_searchHandle(INVALID_HANDLE_VALUE), m_done(false)
{
if(!match) match = "*";
strcpy_s(m_path, sizeof(m_path), path);
char wildcardPath[MAX_PATH];
sprintf_s(wildcardPath, sizeof(wildcardPath), "%s\\%s", path, match);
m_searchHandle = FindFirstFile(wildcardPath, &m_result);
if(m_searchHandle == INVALID_HANDLE_VALUE)
m_done = true;
}
IDirectoryIterator::~IDirectoryIterator()
{
if(m_searchHandle != INVALID_HANDLE_VALUE)
FindClose(m_searchHandle);
}
void IDirectoryIterator::GetFullPath(char * out, UInt32 outLen)
{
sprintf_s(out, outLen, "%s\\%s", m_path, m_result.cFileName);
}
std::string IDirectoryIterator::GetFullPath(void)
{
return std::string(m_path) + "\\" + std::string(m_result.cFileName);
}
void IDirectoryIterator::Next(void)
{
BOOL result = FindNextFile(m_searchHandle, &m_result);
if(!result)
m_done = true;
}
bool IDirectoryIterator::Done(void)
{
return m_done;
}