typedef std::vector<std::string> StringArray;
StringArray ListFiles( const std::string folder, const std::string& pattern )
{
std::string root = folder;
if( root[root.length()-1] != '\\' &&
root[root.length()-1] != '/' )
root += '/';
root += pattern;
StringArray v;
WIN32_FIND_DATA fd;
HANDLE h = FindFirstFile( root.c_str(), &fd);
if( h == INVALID_HANDLE_VALUE )
return v;
if( fd.dwFileAttributes != FILE_ATTRIBUTE_DIRECTORY )
v.push_back(fd.cFileName);
while ( FindNextFile(h, &fd) )
if( fd.dwFileAttributes != FILE_ATTRIBUTE_DIRECTORY )
v.push_back(fd.cFileName);
FindClose( h );
return v;
}
StringArray ListSubfolders( const std::string folder )
{
StringArray v;
std::string root = folder;
if( root[root.length()-1] != '\\' &&
root[root.length()-1] != '/' )
root += '/';
root += "*";
WIN32_FIND_DATA fd;
HANDLE h = FindFirstFile( root.c_str(), &fd);
if( h == INVALID_HANDLE_VALUE )
return v;
if( fd.dwFileAttributes == FILE_ATTRIBUTE_DIRECTORY &&
strcmp( fd.cFileName, "." ) &&
strcmp( fd.cFileName, ".." ) )
{
v.push_back(fd.cFileName);
}
while ( FindNextFile(h, &fd) )
{
if( fd.dwFileAttributes == FILE_ATTRIBUTE_DIRECTORY &&
strcmp( fd.cFileName, "." ) &&
strcmp( fd.cFileName, ".." ) )
{
v.push_back(fd.cFileName);
}
}
FindClose( h );
return v;
}