1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
| /**
* \brief Fonction qui liste les répertoire dans un dossier
* \param strFolder dossier a vérifier
* \return tableau contenant la liste des répertoires
*/
vector<string> ListingFolder(const string& strFolder)
{
WIN32_FIND_DATA File; // Va contenir les informations de la recherche
HANDLE liste = NULL;
vector<string> vReturn = static_cast< vector<string> >(NULL);
vReturn.clear();
int iSize = static_cast<int>(strFolder.size());
char* strTmp = new char[iSize+1];
strncpy(strTmp, strFolder.c_str(), iSize);
if ( strTmp[strlen(strTmp)-1] != '\\')
sprintf(strTmp, "%s\\*.*", strFolder.c_str());
else
sprintf(strTmp, "%s*.*", strFolder.c_str());
//On cherche le premier Fichier
liste = FindFirstFile( strTmp, &File );
if ( liste == INVALID_HANDLE_VALUE )
return static_cast< vector<string> >(NULL);
else
{
if (File.dwFileAttributes == FILE_ATTRIBUTE_DIRECTORY )
{
string strFileName = "\\";
strFileName.append(File.cFileName);
vReturn.push_back(strFolder+strFileName);
}
}
//Tant qu'il existe un fichier suivant
while ( FindNextFile( liste, &File ) )
{
//Si ce fichier est un répertoire
if ( File.dwFileAttributes == FILE_ATTRIBUTE_DIRECTORY )
{
//On ajoute le fichier, à la liste
printf("avant push\n");
string strFileName = "\\";
strFileName.append(File.cFileName);
vReturn.push_back(strFolder+strFileName);
printf("après push\n");
}
}
//On arrete la recherche.
FindClose( liste );
return vReturn;
} |