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

Visual C++ Discussion :

Repertorier le contenu d'un dossier (fichier sous dossier etc..)


Sujet :

Visual C++

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre à l'essai
    Profil pro
    Inscrit en
    Avril 2008
    Messages
    14
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2008
    Messages : 14
    Points : 14
    Points
    14
    Par défaut Repertorier le contenu d'un dossier (fichier sous dossier etc..)
    bonjour,

    je sais ce que vous allez me dire, mais j'ai regardez partout, vraiment et je n'ai toujours pas de solution.

    mon projet est le suivant: transféré tout le contenu d'un dossier (fichiers, sous-dossiers) dans un dossier sur pda. (ex : pput.exe <c:\dossier_source\> <\dossier_cible\>)

    mon problème est le suivant: je n'arrive pas à avoir une gestion efficace des fichiers et des sous dossiers.

    la connexion pc-pda est opérationnel.
    la fonction de "copie-transfère" est opérationnel.
    inutile donc de la poster ici.

    le souci est dans la manière d'utiliser "FindFirstFile" et "FindNextFile".


    voici mon main :
    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
    int main( int argc, char *argv[])
    {
     
        HRESULT hRapiResult;
        int nResult;
     
        if (3 != argc)
        {
            _tprintf( TEXT("Syntax: PPUT <host directory> <wce directory>\n"));
            return 1;
        }
        else
        {
    #ifdef UNICODE
            nResult = MultiByteToWideChar(
                        CP_ACP,    
                        MB_PRECOMPOSED,
                        argv[1],
                        (int) strlen(argv[1])+1,
                        wszSrcDir,
                        ARRAYSIZE(wszSrcDir));
            if(0 == nResult)
            {
    			_tprintf( TEXT("Failed to convert input arguement <host file or directory>\n"));
                return 1;
            }
    #else
            hr = StringCchCopy(wszSrcDir, ARRAYSIZE(wszSrcDir), argv[1]);
            if(FAILED(hr))
            {
    			_tprintf( TEXT("Failed to convert input arguement <host file or directory>\n"));
                return 1;
            }
    #endif
     
    #ifdef UNICODE
    		nResult = MultiByteToWideChar(
    					CP_ACP,    
    					MB_PRECOMPOSED,
    					argv[2],
    					(int) strlen(argv[2])+1,
    					wszDestDir,
    					ARRAYSIZE(wszDestDir));
    		if(0 == nResult)
    		{
    			_tprintf( TEXT("Failed to convert input arguement <wce file or directory>\n"));
    			return 1;
    		}
    #else
            hr = StringCchCopy(wszDestDir, ARRAYSIZE(wszDestDir), argv[2]);
            if(FAILED(hr))
            {
    			_tprintf( TEXT("Failed to convert input arguement <wce file or directory>\n"));
                return 1;
            }
    #endif
    	}
     
        _tprintf( TEXT("Connecting to Windows CE..."));
     
        hRapiResult = CeRapiInit();
     
        if (FAILED(hRapiResult))
        {
            _tprintf( TEXT("Failed\n"));
            return 1;
        }
     
        _tprintf( TEXT("Success\n"));
     
        FoundFile( wszSrcDir, wszDestDir, 0);
     
        _tprintf( TEXT("Closing connection ..."));
        CeRapiUninit();
        _tprintf( TEXT("Done\n"));
     
        return 0;
    }
    dans un premier temps j'ai supprimer le superflus de ma fonction "FoundFile"
    code simplifier de la fonction "FoundFile" :
    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
    int FoundFile(LPWSTR srcPath, LPWSTR destPath, UINT Indent)
    {
        HANDLE hFind;
        DWORD foundCount = 0;
        WIN32_FIND_DATA findFileData;
        WCHAR searchPath[MAX_PATH];
        DWORD *tFileAttribut;
        WCHAR *tFileName;
        int a=0;
     
        _tprintf( TEXT("path : %s\n", srcPath)); // pour afficher le chemin source
        hr = StringCchCopyW(searchPath, ARRAYSIZE(searchPath), srcPath);
        if(FAILED(hr))
        { return 1; }
        hr = StringCchCatW(searchPath, ARRAYSIZE(searchPath), L"*");
        if(FAILED(hr))
        { return 1; }
        _tprintf( TEXT("path : %s\n", searchPath)); // pour afficher le chemin source
     
        hFind = FindFirstFile( searchPath, &findFileData); //recherche du premier fichier
        if (INVALID_HANDLE_VALUE == hFind) // trouver ou pas?
        {
             _tprintf( TEXT("Directory is empty\n")); //pas trouver !!!
             return 1;
        }
        do // trouver
        {
             _tprintf( TEXT("file : %s\n", findFileData.cFileName)); // affiche le nom
    	 a++; // +1 au nb de fichier
    	 foundCount++; // pr un autre délire
     
    	}while(FindNextFile(hFind, &findFileData)); // ba si y'a autre chose c'est reparti pour un tour
    	FindClose( hFind);
     
    	printf("a: %d\n",a); // alors y'en a cmb en tout ??
    	return 0;
    }
    Quand mon dossier est vide, il m'indique qu'il y a 2 fichiers.
    quand j'en rajoute il y a le nb fichier + 2 (tjr ces 2 là, peut etre "." et ".." je ne sais pas).
    ensuite je n'arrive pas avoir le nom des fichiers à l'écran.
    et pour finir, si quelqu'un pouvait me proposer un algo pour gérer les fichiers et les sous dossiers pour ne pas mélanger les fichiers.

    ps : pour info j'arrive à faire le transfère dans l'autre sens pda-pc.

    l'avantage dans ce sens c'est que CeFindAllFiles enregistre toutes les infos dans une structure et j'ai plus qu'à la parcourir pour trouver soit les fichiers et les copier, soit les dossiers et rappeler la fonction en elle meme et rebelote.

    voici le code de la fonction "FoundFile"

    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
    86
    87
    88
    89
    90
    91
    92
    93
    94
    int FoundFile(LPWSTR srcPath, LPWSTR destPath, UINT Indent)
    {
        DWORD          foundCount;
        LPCE_FIND_DATA findDataArray;
        WCHAR searchPath[MAX_PATH];
     
        hr = StringCchCopyW(searchPath, ARRAYSIZE(searchPath), srcPath);
        if(FAILED(hr))
        { return 1; }
        hr = StringCchCatW(searchPath, ARRAYSIZE(searchPath), L"*");
        if(FAILED(hr))
        { return 1; }
     
        if(!CeFindAllFiles(searchPath,
                            FAF_ATTRIBUTES | FAF_NAME,
                            &foundCount,
                            &findDataArray))
        {
            _tprintf( TEXT("*** CeFindAllFiles failed. ***\n"));
            return 1;
        }
     
        if(!foundCount)
            return 1;
     
        for(UINT i = 0; i < foundCount; i++)
        {
            for(UINT indCount = 0; indCount < Indent; indCount++)
                _tprintf( TEXT("  "));
     
            if(findDataArray[i].dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
            {
                _tprintf( TEXT("[%s]\n"),findDataArray[i].cFileName);
                WCHAR newPath[MAX_PATH];
    			WCHAR newDest[MAX_PATH];
     
                hr = StringCchCopyW(newPath, ARRAYSIZE(newPath), srcPath);
                if(FAILED(hr))
                { return 1; }
                hr = StringCchCatW(newPath, ARRAYSIZE(newPath), findDataArray[i].cFileName);
                if(FAILED(hr))
                { return 1; }            
                hr = StringCchCatW(newPath, ARRAYSIZE(newPath), L"\\");
                if(FAILED(hr))
                { return 1; }
     
                hr = StringCchCopyW(newDest, ARRAYSIZE(newDest), destPath);
                if(FAILED(hr))
                { return 1; }
                hr = StringCchCatW(newDest, ARRAYSIZE(newDest), findDataArray[i].cFileName);
                if(FAILED(hr))
                { return 1; }            
                hr = StringCchCatW(newDest, ARRAYSIZE(newDest), L"\\");
                if(FAILED(hr))
                { return 1; }
     
    			hr = CreateDirectory(newDest, NULL);
    			if( hr = 0 )
    			{ return 1; }
     
                FoundFile(newPath, newDest, Indent + 1);
            }
            else
            {
                _tprintf( TEXT("%s\n"),findDataArray[i].cFileName);
     
    			WCHAR srcCopyFile[MAX_PATH];
    			WCHAR destCopyFile[MAX_PATH];
     
    			hr  = StringCchCopyW(srcCopyFile, ARRAYSIZE(srcCopyFile), srcPath);
    			if(FAILED(hr))
    			{ return 1; }
    			hr  = StringCchCatW(srcCopyFile, ARRAYSIZE(srcCopyFile), findDataArray[i].cFileName);
    			if(FAILED(hr))
    			{ return 1; }
     
    			hr  = StringCchCopyW(destCopyFile, ARRAYSIZE(destCopyFile), destPath);
    			if(FAILED(hr))
    			{ return 1; }
    			hr  = StringCchCatW(destCopyFile, ARRAYSIZE(destCopyFile), findDataArray[i].cFileName);
    			if(FAILED(hr))
    			{ return 1; }
     
    			FileCopy( srcCopyFile, destCopyFile);
            }
        }
     
    	if (findDataArray)
        {
            RapiFreeBuffer(findDataArray);
        }
     
    	return 0;
    }
    Merci

  2. #2
    Membre émérite
    Avatar de TheGzD
    Homme Profil pro
    Ingénieur/ Docteur en Informatique
    Inscrit en
    Avril 2007
    Messages
    1 327
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 42
    Localisation : France, Puy de Dôme (Auvergne)

    Informations professionnelles :
    Activité : Ingénieur/ Docteur en Informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Avril 2007
    Messages : 1 327
    Points : 2 677
    Points
    2 677
    Par défaut
    je sais ce que vous allez me dire
    oui en effet tu peux t'en douter, car tu n'as visiblement même pas pris la peine de lire la FAQ dont je t'ai donné le lien dans ton dernier post ...
    Vous postez du code ? Merci d'utiliser les balises
    Un message vous paraît pertinent ? Merci de le gratifier d'un vote positif
    Vous avez obtenu une réponse à votre question ? Merci d'utiliser le tag
    __________________
    Ingénieur R&D, diplômé en 2007 de l'ISIMA
    Docteur en informatique, diplômé en 2015 de l'EDSPI de Clermont-Ferrand

  3. #3
    Inactif  
    Avatar de Mac LAK
    Profil pro
    Inscrit en
    Octobre 2004
    Messages
    3 893
    Détails du profil
    Informations personnelles :
    Âge : 49
    Localisation : France, Haute Garonne (Midi Pyrénées)

    Informations forums :
    Inscription : Octobre 2004
    Messages : 3 893
    Points : 4 846
    Points
    4 846
    Par défaut
    Et sinon, un simple printf / cout t'aurais permis de voir quels étaient les noms des fichiers "en trop", pour effectivement constater que les deux premiers sont toujours ".", suivi de "..", sauf pour le répertoire racine...

    De plus, tu as un code exemple sur MSDN.
    Mac LAK.
    ___________________________________________________
    Ne prenez pas la vie trop au sérieux, de toutes façons, vous n'en sortirez pas vivant.

    Sources et composants Delphi sur mon site, L'antre du Lak.
    Pas de question technique par MP : posez-la dans un nouveau sujet, sur le forum adéquat.

    Rejoignez-nous sur : Serveur de fichiers [NAS] Le Tableau de bord projets Le groupe de travail ICMO

  4. #4
    Membre à l'essai
    Profil pro
    Inscrit en
    Avril 2008
    Messages
    14
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2008
    Messages : 14
    Points : 14
    Points
    14
    Par défaut
    j'ai lu la FAQ et l'exemple sur MSDN. voici ce que me retourne printf.
    C:\Prog...\Pput2\Release>pput2.exe c:\test1\ \test2\
    Connecting to Windows CE...Success
    path : ??????F
    path : ??????F
    file : ??????F
    file : ??????F
    file : ??????F
    file : ??????F
    file : ??????F
    file : ??????F
    a: 6
    Closing connection ...Done
    désoler de pas tout comprendre. et merci de vos commentaire pertinant.

  5. #5
    Inactif  
    Avatar de Mac LAK
    Profil pro
    Inscrit en
    Octobre 2004
    Messages
    3 893
    Détails du profil
    Informations personnelles :
    Âge : 49
    Localisation : France, Haute Garonne (Midi Pyrénées)

    Informations forums :
    Inscription : Octobre 2004
    Messages : 3 893
    Points : 4 846
    Points
    4 846
    Par défaut
    Windows CE ne travaille qu'en Unicode, c'est bien martelé dans tous les cours d'intro à cet OS : il faut donc que tu compiles ton projet sur PC en Unicode également si tu veux réussir à comprendre ce qu'il t'affiche...
    Mac LAK.
    ___________________________________________________
    Ne prenez pas la vie trop au sérieux, de toutes façons, vous n'en sortirez pas vivant.

    Sources et composants Delphi sur mon site, L'antre du Lak.
    Pas de question technique par MP : posez-la dans un nouveau sujet, sur le forum adéquat.

    Rejoignez-nous sur : Serveur de fichiers [NAS] Le Tableau de bord projets Le groupe de travail ICMO

  6. #6
    Membre à l'essai
    Profil pro
    Inscrit en
    Avril 2008
    Messages
    14
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2008
    Messages : 14
    Points : 14
    Points
    14
    Par défaut
    j'ai trouver un départ de solution à mon problème qui est tjr le même.

    Pour l'affichage, si vous aviez jeter un œil à mon code vous auriez vu que :
    erreurs dans les parenthèses:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    _tprintf( TEXT("path : %s\n", srcPath));
    erreurs corriger :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    _tprintf( TEXT("path : %s\n"), srcPath);
    et ca affiche bien les caractères et pour l'histoire du UNICODE, j'avais dejà configurer VS mais merci.

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

Discussions similaires

  1. [AC-2007] Code pour supprimer tous les fichiers, sous-dossiers d'un dossier
    Par lio33 dans le forum VBA Access
    Réponses: 2
    Dernier message: 07/04/2015, 19h26
  2. Réponses: 4
    Dernier message: 30/10/2014, 23h08
  3. [XL-2002] Recherche fichier dans dossier et sous dossier
    Par thomasdu40 dans le forum Macros et VBA Excel
    Réponses: 12
    Dernier message: 29/02/2012, 12h09
  4. Compter fichier de dossiers et sous-dossiers
    Par thomas1806 dans le forum Macros et VBA Excel
    Réponses: 6
    Dernier message: 21/07/2009, 14h59
  5. Réponses: 6
    Dernier message: 15/04/2008, 18h46

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