IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Développement OS X Discussion :

[Carbon] Scanner un dossier a la recherche de certains fichiers


Sujet :

Développement OS X

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre éprouvé
    Avatar de NiamorH
    Inscrit en
    Juin 2002
    Messages
    1 309
    Détails du profil
    Informations forums :
    Inscription : Juin 2002
    Messages : 1 309
    Points : 1 051
    Points
    1 051
    Par défaut [Carbon] Scanner un dossier a la recherche de certains fichiers
    Bonjour,
    j'essaye de parcourir les fichiers .tga situés dans un dossier particulier et dont le nom commence par une certaine chaine de caractere.
    Ces deux informations sont stockees dans l'objet Sequence et sont accessible via getRepertoire() et getNom() qui renvoient des char*.

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    /**
     * @brief Scanne le dossier de la sequence pour lui ajouter les bons pointeurs images
     * @param sequence La sequence a remplir
     */
    void
    Chargeur::scannerSequence(Sequence* sequence)
    {
    #if defined MACOSX
      FSRef fs_rep;
      FSIterator fs_it;
      
      FSPathMakeRef((uchar*)sequence->getRepertoire(), &fs_rep, 0);
      FSOpenIterator(&fs_rep, kFSIterateFlat, &fs_it);
      
      FSSearchParams criteres_recherche;
      FSCatalogInfo			searchInfo1;
      FSCatalogInfo			searchInfo2;
    	
    	
    	/*
    	 * Initialize the searchCriteria, the searchInfo1 and the searchInfo2 records.
    	 * These tell FSCatalogSearch what to find.
    	 */
    	criteres_recherche.searchTime 		= 0;					/* timeout as used by a Time Manager task, or 0 for no timeout */
    	criteres_recherche.searchBits		= fsSBPartialName + fsSBFlAttrib;		/* fields to look at in searchInfo1 and searchInfo2 structs */
    	criteres_recherche.searchName		= (UniChar*) sequence->getNom();
    	criteres_recherche.searchNameLength = strlen(sequence->getNom());
    	criteres_recherche.searchInfo1		= &searchInfo1;			/* the catalog info to match */
    	criteres_recherche.searchInfo2		= &searchInfo2;			/* the catalog info mask */
    	
    	/* only match files (not directories) */
    	searchInfo1.nodeFlags			= 0;						/* kFSNodeIsDirectoryBit set to 0 for files */ 
    	searchInfo2.nodeFlags			= kFSNodeIsDirectoryMask;	/* check only this nodeFlag bit */
    	
    	/* search for this fileType */
    	((FileInfo *)&searchInfo1.finderInfo)->fileType = 'TGA'; /* AppleWorks WP files */
    	((FileInfo *)&searchInfo2.finderInfo)->fileType = (OSType)0xffffffff;
    	
    	/* search for this fileCreator */
    //	((FileInfo *)&searchInfo1.finderInfo)->fileCreator = 'BOBO'; /* AppleWorks */
    //	((FileInfo *)&searchInfo2.finderInfo)->fileCreator = (OSType)0xffffffff;
    	
    	/* find only visible files */
    	((FileInfo *)&searchInfo1.finderInfo)->finderFlags = 0;
    	((FileInfo *)&searchInfo2.finderInfo)->finderFlags = kIsInvisible;
    
    	/* zero all other FileInfo fields */
    	((FileInfo *)&searchInfo1.finderInfo)->location.v = 0;
    	((FileInfo *)&searchInfo1.finderInfo)->location.h = 0;
    	((FileInfo *)&searchInfo1.finderInfo)->reservedField = 0;
    	
    	((FileInfo *)&searchInfo2.finderInfo)->location.v = 0;
    	((FileInfo *)&searchInfo2.finderInfo)->location.h = 0;
    	((FileInfo *)&searchInfo2.finderInfo)->reservedField = 0;
    	
      // nombre de fichiers trouves (1 ou 0)
      ulong nb_trouve;
      FSRef fs_image;
      HFSUniStr255 nom_image;
      
      while (FSCatalogSearch( fs_it, &criteres_recherche, 1, &nb_trouve, 0, kFSCatInfoNone, 0, &fs_image, 0, &nom_image) != errFSNoMoreItems)
      {
        CFStringRef str = CFStringCreateWithCharacters( kCFAllocatorDefault, 
                                                           nom_image.unicode, nom_image.length );
        char* output = NewPtr(CFStringGetLength(str)+1);
    	// check output for NULL
    	CFStringGetCString(str, output, CFStringGetLength(str)+1, kCFStringEncodingMacRoman);
        CFRelease( str );
        fprintf(stderr,"%s\n",output);
    	
    	delete output;
      }
    
    #elif defined WINDOWS
    
    #endif
    
    }
    Voila ce que j'obtiens :

    Citation Envoyé par la console
    objects.nib
    InfoPlist.strings
    Localizable.strings
    keyedobjects.nib
    objects.nib
    objects.nib
    keyedobjects.nib
    keyedobjects.nib
    objects.nib
    InfoPlist.strings
    Localizable.strings
    keyedobjects.nib
    objects.nib
    objects.nib
    keyedobjects.nib
    keyedobjects.nib
    objects.nib
    InfoPlist.strings
    Localizable.strings
    keyedobjects.nib
    objects.nib
    objects.nib
    keyedobjects.nib
    keyedobjects.nib
    objects.nib
    J'avoue avoir copié des bouts de codes récupérés à droite à gauche mais je vois pas trop ce qui cloche. Quelqu'un peut -il m'aiguiller ?

    merci

  2. #2
    Membre éprouvé
    Avatar de NiamorH
    Inscrit en
    Juin 2002
    Messages
    1 309
    Détails du profil
    Informations forums :
    Inscription : Juin 2002
    Messages : 1 309
    Points : 1 051
    Points
    1 051
    Par défaut
    Le nom de la sequence n'etait pas bon, mais maintenant je n'ai plus aucune réponse dans la console.

  3. #3
    Expert confirmé
    Homme Profil pro
    Inscrit en
    Septembre 2006
    Messages
    2 942
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Belgique

    Informations forums :
    Inscription : Septembre 2006
    Messages : 2 942
    Points : 4 363
    Points
    4 363
    Par défaut
    Citation Envoyé par NiamorH
    Le nom de la sequence n'etait pas bon, mais maintenant je n'ai plus aucune réponse dans la console.
    1. un type de fichier de 3 caractères 'TGA' est suspect : vérifiez s'il ne manque pas une espace ('TGA '), (… serait bête de perdre son temps pour une erreur de frappe…)
    (n'oubliez pas que sous OS X, le remplissage du fileType n'est pas toujours respecté, l'extention pouvant suffire pour identifier le type de fichier…)

    2. strlen() sur un buffer Unicode n'a pas de sens…

  4. #4
    Membre éprouvé
    Avatar de NiamorH
    Inscrit en
    Juin 2002
    Messages
    1 309
    Détails du profil
    Informations forums :
    Inscription : Juin 2002
    Messages : 1 309
    Points : 1 051
    Points
    1 051
    Par défaut
    J'ai modifié un peu le code mais je n'ai rien de concluant.
    Quelqu'un sait comment faire de maniere simple? Je ne comprend vraiment pas les sources que je trouve et la reference sur le site d'apple est pas tres claire.

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
      FSRef fs_rep;
      FSIterator fs_it;
      
      if (FSPathMakeRef((uchar*)sequence->getRepertoire(), &fs_rep, 0) == fnfErr)
      {  
    	fprintf(stderr,"Repertoire non trouve %s\n",sequence->getRepertoire());
    	return;
      }
      
      if (FSOpenIterator(&fs_rep, kFSIterateFlat, &fs_it))
      {
        fprintf(stderr,"Iterateur non valide %s\n",sequence->getRepertoire());
        return;
      }
      
      CFStringRef str;
      char nom_seq_unicode[256];
     
      str = CFStringCreateWithCString(NULL, sequence->getNom(), kCFStringEncodingMacRoman);
      CFStringGetCString( str, nom_seq_unicode, 256, kCFStringEncodingUnicode );	//	Get the unicode string
      
    	
      FSSearchParams criteres_recherche;
      FSCatalogInfo			searchInfo1;
      FSCatalogInfo			searchInfo2;
    	
    	
    	//
    	//  Initialize the searchCriteria, the searchInfo1 and the searchInfo2 records.
    	//  These tell FSCatalogSearch what to find.
    	//
    	criteres_recherche.searchTime 		= 0;					// timeout as used by a Time Manager task, or 0 for no timeout 
    	criteres_recherche.searchBits		= fsSBPartialName + fsSBFlAttrib;		// fields to look at in searchInfo1 and searchInfo2 structs 
    	criteres_recherche.searchName		= (UniChar*)nom_seq_unicode;
    	criteres_recherche.searchNameLength = CFStringGetLength(str);
    	criteres_recherche.searchInfo1		= &searchInfo1;			// the catalog info to match 
    	criteres_recherche.searchInfo2		= &searchInfo2;			// the catalog info mask 
    	
    	// only match files (not directories)
    	searchInfo1.nodeFlags			= 0;						// kFSNodeIsDirectoryBit set to 0 for files
    	searchInfo2.nodeFlags			= kFSNodeIsDirectoryMask;	// check only this nodeFlag bit
    	
    	// search for this fileType 
    //	((FileInfo *)&searchInfo1.finderInfo)->fileType = 'TGA'; // AppleWorks WP files 
    //	((FileInfo *)&searchInfo2.finderInfo)->fileType = (OSType)0xffffffff;
    	
    	// search for this fileCreator 
    //	((FileInfo *)&searchInfo1.finderInfo)->fileCreator = 'BOBO'; // AppleWorks
    //	((FileInfo *)&searchInfo2.finderInfo)->fileCreator = (OSType)0xffffffff;
    	
    	// find only visible files 
    	((FileInfo *)&searchInfo1.finderInfo)->finderFlags = 0;
    	((FileInfo *)&searchInfo2.finderInfo)->finderFlags = kIsInvisible;
    
    	// zero all other FileInfo fields 
    	((FileInfo *)&searchInfo1.finderInfo)->location.v = 0;
    	((FileInfo *)&searchInfo1.finderInfo)->location.h = 0;
    	((FileInfo *)&searchInfo1.finderInfo)->reservedField = 0;
    	
    	((FileInfo *)&searchInfo2.finderInfo)->location.v = 0;
    	((FileInfo *)&searchInfo2.finderInfo)->location.h = 0;
    	((FileInfo *)&searchInfo2.finderInfo)->reservedField = 0;
    	
      // nombre de fichiers trouves (1 ou 0)
      ulong nb_trouve;
      FSRef fs_image;
      HFSUniStr255 nom_image;
      OSErr err;
    
      err = FSCatalogSearch( fs_it, &criteres_recherche, 1, &nb_trouve, 0, kFSCatInfoNone, 0, &fs_image, 0, &nom_image);
      while ( !err )
      {
        CFStringRef str = CFStringCreateWithCharacters( kCFAllocatorDefault, 
                                                           nom_image.unicode, nom_image.length );
        char* output = NewPtr(CFStringGetLength(str)+1);
    	// check output for NULL
    	CFStringGetCString(str, output, CFStringGetLength(str)+1, kCFStringEncodingMacRoman);
        CFRelease( str );
        fprintf(stderr,"%s\n",output);
    // TODO	
    	delete output;
    	err = FSCatalogSearch( fs_it, &criteres_recherche, 1, &nb_trouve, 0, kFSCatInfoNone, 0, &fs_image, 0, &nom_image);
      }
      
      fprintf(stderr, "sortie : %d \n", err);

  5. #5
    Membre éprouvé
    Avatar de NiamorH
    Inscrit en
    Juin 2002
    Messages
    1 309
    Détails du profil
    Informations forums :
    Inscription : Juin 2002
    Messages : 1 309
    Points : 1 051
    Points
    1 051
    Par défaut
    On m'a finalement conseillé de ne pas utiliser FSCatalogSearch mais FSGetCatalogInfoBulk.

    Ca marche bien maintenant :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    56
    57
    58
    59
    60
    61
    62
    63
    64
    #include <CoreServices/CoreServices.h>
     #include <iostream>
     
     
    int main()
    {
    
      FSRef fs_rep;
      
      FSIterator fs_it;
      
       if (FSPathMakeRef((unsigned char*)"/Users/lionelfages/Desktop/test/", &fs_rep, 0) == fnfErr)
      {  
    	fprintf(stderr,"Repertoire non trouve %s\n","lkjh");
    	return 0;
      }
      
      if (FSOpenIterator(&fs_rep, kFSIterateFlat, &fs_it))
      {
        fprintf(stderr,"Iterateur non valide %s\n","ljkhglj");
        return 0;
      }
      
    
    
    ItemCount actualObjects;
    HFSUniStr255 unicodeName;
    FSCatalogInfo catalogInfo;
    FSRef documentFSRef;
    
    OSErr err;
    
    err=FSGetCatalogInfoBulk(fs_it,1,&actualObjects,NULL,kFSCatInfoNodeFlags,&catalogInfo,&documentFSRef,NULL,&unicodeName);
    while(err==noErr)
    {
    	CFStringRef strRef;
    	char * chaine;
    	
    	/* Extraction des informations du node suivant*/
    	strRef=CFStringCreateWithCharacters(kCFAllocatorDefault, unicodeName.unicode, unicodeName.length);
    	if(!CFStringGetCString(strRef, chaine, 256, kCFStringEncodingUTF8))
    	{
    		/* Erreur a la conversion de nom */
    		strcpy(chaine,"");
    	}
    	else
    	{
    		/* Dois t'on extraire les noms de dossier ? */
    		if(catalogInfo.nodeFlags & kFSNodeIsDirectoryMask)
    		{
    			//if(finfo->masqueAttrib & _A_SUBDIR) Ok=true;
    			//else Ok=false;
    			//finfo->attrib=_A_SUBDIR;
    		  fprintf(stderr,"hello dossier %s\n", chaine);
    		}
    		else
    		  fprintf(stderr,"hello fichier %s\n", chaine);
    			//Ok=IsFileMatchMask(chaine,finfo->masque);
    	}
    	CFRelease(strRef);
    	err=FSGetCatalogInfoBulk(fs_it,1,&actualObjects,NULL,kFSCatInfoNodeFlags,&catalogInfo,&documentFSRef,NULL,&unicodeName);
    }
    return(err);
    }

  6. #6
    Membre éprouvé

    Profil pro
    Inscrit en
    Janvier 2005
    Messages
    733
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Janvier 2005
    Messages : 733
    Points : 1 119
    Points
    1 119
    Par défaut
    Citation Envoyé par NiamorH
    On m'a finalement conseillé de ne pas utiliser FSCatalogSearch mais FSGetCatalogInfoBulk.

    Ca marche bien maintenant :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    56
    57
    58
    59
    60
    61
    62
    63
    64
    #include <CoreServices/CoreServices.h>
     #include <iostream>
     
     
    int main()
    {
    
      FSRef fs_rep;
      
      FSIterator fs_it;
      
       if (FSPathMakeRef((unsigned char*)"/Users/lionelfages/Desktop/test/", &fs_rep, 0) == fnfErr)
      {  
    	fprintf(stderr,"Repertoire non trouve %s\n","lkjh");
    	return 0;
      }
      
      if (FSOpenIterator(&fs_rep, kFSIterateFlat, &fs_it))
      {
        fprintf(stderr,"Iterateur non valide %s\n","ljkhglj");
        return 0;
      }
      
    
    
    ItemCount actualObjects;
    HFSUniStr255 unicodeName;
    FSCatalogInfo catalogInfo;
    FSRef documentFSRef;
    
    OSErr err;
    
    err=FSGetCatalogInfoBulk(fs_it,1,&actualObjects,NULL,kFSCatInfoNodeFlags,&catalogInfo,&documentFSRef,NULL,&unicodeName);
    while(err==noErr)
    {
    	CFStringRef strRef;
    	char * chaine;
    	
    	/* Extraction des informations du node suivant*/
    	strRef=CFStringCreateWithCharacters(kCFAllocatorDefault, unicodeName.unicode, unicodeName.length);
    	if(!CFStringGetCString(strRef, chaine, 256, kCFStringEncodingUTF8))
    	{
    		/* Erreur a la conversion de nom */
    		strcpy(chaine,"");
    	}
    	else
    	{
    		/* Dois t'on extraire les noms de dossier ? */
    		if(catalogInfo.nodeFlags & kFSNodeIsDirectoryMask)
    		{
    			//if(finfo->masqueAttrib & _A_SUBDIR) Ok=true;
    			//else Ok=false;
    			//finfo->attrib=_A_SUBDIR;
    		  fprintf(stderr,"hello dossier %s\n", chaine);
    		}
    		else
    		  fprintf(stderr,"hello fichier %s\n", chaine);
    			//Ok=IsFileMatchMask(chaine,finfo->masque);
    	}
    	CFRelease(strRef);
    	err=FSGetCatalogInfoBulk(fs_it,1,&actualObjects,NULL,kFSCatInfoNodeFlags,&catalogInfo,&documentFSRef,NULL,&unicodeName);
    }
    return(err);
    }

    Merci d''avoir poster le code qui fonctionne, n'oublie de mettre le tag résolu(en editant ton poste).

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. [WD14] scanner un dossier sous WD
    Par robin.lodeon dans le forum WinDev
    Réponses: 2
    Dernier message: 21/01/2010, 15h04
  2. Scanner un dossier contenant des photos
    Par kesmo dans le forum Langage
    Réponses: 2
    Dernier message: 09/01/2010, 14h51
  3. Recherche de Certains Fichiers Initiaux de Vista
    Par Danyel dans le forum Windows Vista
    Réponses: 5
    Dernier message: 15/01/2009, 17h01
  4. scanner des dossiers et les mettre dans une liste
    Par niklos0 dans le forum Programmation et administration système
    Réponses: 1
    Dernier message: 08/09/2008, 14h34
  5. scanner des dossiers
    Par dkoneeee dans le forum VB 6 et antérieur
    Réponses: 4
    Dernier message: 26/07/2007, 20h51

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo