Recherche fichier code c aidez moi svp

zilot2 Messages postés 8 Date d'inscription samedi 25 octobre 2008 Statut Membre Dernière intervention 15 novembre 2009 - 19 sept. 2009 à 23:27
cs_rt15 Messages postés 3874 Date d'inscription mardi 8 mars 2005 Statut Modérateur Dernière intervention 7 novembre 2014 - 20 sept. 2009 à 18:06
bonjours et pardonnez mon français , mon code est de rechercher un fichier dans tous les repertoires. voici mon code:


#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
#include <dirent.h>
#include <string.h>
char scanforexe( HANDLE ffind, WIN32_FIND_DATA ffdata){
int i;
ffind=FindFirstFile("*.exe*", &ffdata);
i=strcmp("lilo3.exe",ffdata.cFileName);
printf ("The first file found is %s \n", ffdata.cFileName);
while (FindNextFile(ffind, &ffdata) != 0 && (i!=0)) {
printf("the next files are: %s \n",ffdata.cFileName);
i=strcmp("lilo3.exe",ffdata.cFileName) }
if(i==0){printf(" file found ");}
return 0;
char scanfloder(HANDLE ffind ,WIN32_FIND_DATA ffdata,char *dir){
int i,j=strlen(dir);
strcat(dir,"*.*");
printf("%s\n",dir);

scanforexe( ffind, ffdata);

ffind=FindFirstFile("*.*", &ffdata);
printf ("The first floder found is %s \n", ffdata.cFileName);


while (FindNextFile(ffind, &ffdata) != 0 ) {
if (ffdata.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
{printf("the next floder is : %s \n",ffdata.cFileName);
if(strcmp(ffdata.cFileName,".")!=0 && strcmp(ffdata.cFileName,"..")!=0)
{
for( i=j;i<strlen(dir);i++){
dir[i]='\0';
}
printf("%s\n",dir);
concat(dir,ffdata.cFileName);

SetCurrentDirectory(dir);
strcat(dir,"\" ) ;
printf("%s\n",dir);
printf("%s\n",ffdata.cFileName);
scanfloder(ffind,ffdata,dir);

}

}
}




FindClose(ffind);
return 0;

}
int main()
{



char *dir1="D:\" ;
char *dir;
strcpy(dir,dir1);


WIN32_FIND_DATA ffdata;
HANDLE ffind;

SetCurrentDirectory(dir);
scanfloder(ffind,ffdata,dir);
return 0;
}


le probleme mon code ne scan pas tous les dossiers s'il vous plais aidez moi.montrez moi l'erreur et merci.

2 réponses

cs_rt15 Messages postés 3874 Date d'inscription mardi 8 mars 2005 Statut Modérateur Dernière intervention 7 novembre 2014 13
20 sept. 2009 à 18:04
Salut,

Si tu utilises "*.*" pour chercher les répertoires, tu ne vas effectivement pas aller bien loin. Utilise "*".
0
cs_rt15 Messages postés 3874 Date d'inscription mardi 8 mars 2005 Statut Modérateur Dernière intervention 7 novembre 2014 13
20 sept. 2009 à 18:06
Et pense à ".." et ".".

Voilà un bout d'exemple (Qui sera loin de compiler en l'état...):
BOOL RT_API FileSys_EnumDir(TCHAR* lpPath, FILESYS_ENUMDIRPROC lpCallBack)
{
  WIN32_FIND_DATA findFileData;    /* Information sur les fichiers trouvés    */
  HANDLE hFind;                    /* Handle sur la recherche                 */
  TCHAR lpDir[FILESYS_MAX_PATH];   /* Chemin de travail                       */
  BOOL bRes;

  bRes = FALSE;

  /* Appel de la callback */
  if (! lpCallBack(lpPath))
    goto the_end;

  /* Parcourt récursif */
  lstrcpy(lpDir, lpPath);
  lstrcat(lpDir, _T("\\*"));
  hFind = FindFirstFile(lpDir, &findFileData);
  if (hFind == INVALID_HANDLE_VALUE)
  {
    if (GetLastError() == ERROR_FILE_NOT_FOUND)
      bRes = TRUE;
    goto the_end;
  }

  do
  {
    if (findFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
      if (lstrcmp(_T("."), findFileData.cFileName) &&
         lstrcmp(_T(".."), findFileData.cFileName))
      {
        lstrcpy(lpDir, lpPath);
        lstrcat(lpDir, _T("\"));
        lstrcat(lpDir, findFileData.cFileName);
        if (! FileSys_EnumDir(lpDir, lpCallBack))
          goto the_end;
      }
  }
  while (FindNextFile(hFind, &findFileData));
  FindClose(hFind);

  /* Vérification que l'on est sorti de le la boucle */
  /* car il n'y a plus de fichiers.                  */
  if (GetLastError() == ERROR_NO_MORE_FILES)
    bRes = TRUE;

the_end:
  return bRes;
}
0
Rejoignez-nous