BOOL GetFileInFolder(LPCTSTR pFolder, LPCTSTR pFilter, bool bSubFolder,
std::vector<string> &vecFilename)
{
if (!pFolder || !PathFileExists(pFolder))
{
return FALSE;
}

 
vecFilename.clear();

 
string strFolder = pFolder;
if(*(strFolder.end()-1) != _T('\\'))
strFolder += _T("\\");

 
if(!pFilter) pFilter = _T("*.*");
const string strFindFileName = strFolder + pFilter;

 
WIN32_FIND_DATA wfd;
RtlZeroMemory(&wfd, sizeof(wfd));
HANDLE hFind = FindFirstFile(strFindFileName.c_str(), &wfd);
if(hFind == INVALID_HANDLE_VALUE) return false;

 
BOOL bNext = TRUE;
while(bNext) {
string strFound = strFolder+wfd.cFileName;
if(wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
if(!bSubFolder || _tcscmp(wfd.cFileName, _T(".")) == 0 || _tcscmp(wfd.cFileName, _T("..")) == 0) {
bNext = FindNextFile(hFind, &wfd);
continue;
}

 
std::vector<string> vecTemp;
if(GetFileInFolder(strFound.c_str(), pFilter, bSubFolder, vecTemp) && !vecTemp.empty())
vecFilename.insert(vecFilename.end(), vecTemp.begin(), vecTemp.end());

 
bNext = FindNextFile(hFind, &wfd);
continue;
}

 
vecFilename.push_back(strFound);
bNext = FindNextFile(hFind, &wfd);
}

 
if(hFind != INVALID_HANDLE_VALUE)
FindClose(hFind);

 
return true;
}