Coment faites-vous pour parcourir recursivement des dossiers (surDOS/WINDOWS) ?
Perso, j'ai l'impression de sortir l'artillerie lourde (A cas de flux de fichiers -POSIX- et de chdir)...
WIN32_FIND_DATA wData;
void lister(LPCTSTR fichier,char chemin[MAX_PATH])
{
char chemin1[MAX_PATH],chemin2[MAX_PATH],chemin3[MAX_PATH],chemin4[MAX_PATH];
for(i=0;i<MAX_PATH;i++)
{
chemin1[i]='\0';
chemin2[i]='\0';
}
for(i=0;i<(int)strlen(chemin);i++)
chemin1[i]=chemin[i];
for(i=0;i<(int)strlen(chemin1);i++)
chemin2[i]=chemin1[i];
strcat(chemin2,"*.*");
HANDLE listing;
listing=FindFirstFile(fichier,&wData);
while((FindNextFile(listing,&wData)))
{
nom=wData.cFileName;
for(i=0;i<MAX_PATH;i++)
{
nom_complet[i]='\0';
}
for(i=0;i<(int)strlen(chemin1);i++)
nom_complet[i]=chemin[i];
for(i=strlen(chemin1);i<(int)strlen(chemin1)+(int)strlen(nom);i++)
nom_complet[i]=nom[i-strlen(chemin1)];
if(_chdir(nom_complet)==-1) trouvepoint="1";
if((trouvepoint==NULL)&&((nom[0]!='.')||(nom[1]!='.')))
{
for(i=0;i<MAX_PATH;i++)
{
chemin3[i]='\0';
chemin4[i]='\0';
}
strcpy(chemin3,nom_complet);
strcpy(chemin4,nom_complet);
strcat(chemin4,"\*.*");
strcat(chemin3,"\");
lister(chemin4,chemin3);
}
trouvepoint=NULL;
}
}
Voila ce que j'ai fait :
/*
* You should set the drive before calling this function
* path must be a full path (not a relative path).
* filter should not contain path.
* Current directory must be set to path
*/
void scandir(const char *path, const char *filter)
{
struct ffblk f;
int done;
// First pass : get the selected files.
done = findfirst(filter, &f, 0);
while (!done)
{
// Do stuff
printf("%s\n",f.ff_name);
// Next file
done = findnext(&f);
}
// Second pass : Go through the sub-directories
done = findfirst("*", &f, FA_DIREC);
while (!done)
{
if (strcmp(f.ff_name, "..") && strcmp(f.ff_name, "."))
{
char NewPath[MAXPATH];
sprintf(NewPath,"%s\%s", path, f.ff_name);
if (chdir(NewPath) == 0)
{
scandir(NewPath, filter);
chdir(path);
}
}
// Next file
done = find
