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++

  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 : 41
    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.

  7. #7
    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
    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
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    #include <windows.h>
    #include <list>
    #include <string>
    #include <tchar.h>
    #include <stdio.h>
    #include <string.h>
    #include <rapi.h>
    #include <strsafe.h>
     
    using namespace std;
     
    #define ARRAYSIZE(x) (sizeof(x)/sizeof(x[0]))
     
    WCHAR wszDestDir[MAX_PATH];
    WCHAR wszSrcDir[MAX_PATH];
    WCHAR wszSrcFile[MAX_PATH];
    WCHAR wszDestFile[MAX_PATH];
    BYTE  Buffer[4096];
    HRESULT hr;
     
    int FileCopy(LPCWSTR wszSrcFile, LPCWSTR wszDestFile)
    {
    	HANDLE hSrc, hDest;
        DWORD dwNumRead, dwNumWritten;
     
    	hSrc = CreateFile(
                    wszSrcFile,
                    GENERIC_READ,
                    FILE_SHARE_READ,
                    NULL,
                    OPEN_EXISTING,
                    FILE_ATTRIBUTE_NORMAL,
                    NULL);
        if (INVALID_HANDLE_VALUE == hSrc)
        {
            _tprintf( TEXT("Unable to open source/host file\n"));
            return 1;
        }
     
        hDest = CeCreateFile(
                    wszDestFile,
                    GENERIC_WRITE,
                    FILE_SHARE_READ,
                    NULL,
                    CREATE_ALWAYS,
                    FILE_ATTRIBUTE_NORMAL,
                    NULL);
     
        if (INVALID_HANDLE_VALUE == hDest )
        {
            _tprintf( TEXT("Unable to open WinCE file\n"));
            return 1;
        }
    #ifdef UNICODE
        wprintf( TEXT("Copying %s to WCE:%s\n"), wszSrcFile, wszDestFile);
    #else
        printf( TEXT("Copying %s to WCE:%S\n"), wszSrcFile, wszDestFile);
    #endif
     
        do
        {
            if (ReadFile(
                    hSrc,
                    &Buffer,
                    sizeof(Buffer),
                    &dwNumRead,
                    NULL))
            {
                if (!CeWriteFile(
                        hDest,
                        &Buffer,
                        dwNumRead,
                        &dwNumWritten,
                        NULL))
                {
                    _tprintf( TEXT("Error !!! Writing WinCE file\n"));
    				CeCloseHandle( hDest);
    				CloseHandle (hSrc);
                    return 1;
                }
            }
            else
            {
                _tprintf( TEXT("Error !!! Reading source file\n"));
    			CeCloseHandle( hDest);
    			CloseHandle (hSrc);
                return 1;
            }
            _tprintf( TEXT("."));                                        
        } while (dwNumRead);
        _tprintf( TEXT("\n"));    
     
    	return 0;
     
    }
     
    class myFileInfo
    {
    private:
    	wstring	mFileName;
    	DWORD	mFileType;
     
    public:
    	myFileInfo() {} 
    	~myFileInfo() {}
     
    	wstring getFileName() {
    		return mFileName;
    	}
    	DWORD getFileType() {
    		return mFileType;
    	}
    	void setFileName(wstring name) {
    		mFileName = name;
    	}
    	void setFileType(DWORD type) {
    		mFileType = type;
    	}
     
    };
     
    int FoundFile(LPWSTR srcPath, LPWSTR destPath, UINT Indent)
    {
    	HANDLE hFind;
    	WIN32_FIND_DATA findFileData;
    	WCHAR searchPath[MAX_PATH];
     
    	int foundCount = 0;
     
    	list<myFileInfo> strList;
     
        hr = StringCchCopyW(searchPath, ARRAYSIZE(searchPath), srcPath);
        if(FAILED(hr))
        { return 1; }
        hr = StringCchCatW(searchPath, ARRAYSIZE(searchPath), L"*");
        if(FAILED(hr))
        { return 1; }
     
    	hFind = FindFirstFile( searchPath, &findFileData);
    	if (INVALID_HANDLE_VALUE == hFind )
        {
    		_tprintf( TEXT("Directory is empty\n"));
            return 1;
    	}
    	do
    		{
    			if (lstrcmp(findFileData.cFileName,L".") == 0 || lstrcmp(findFileData.cFileName,L"..") == 0)
    			{
    				//_tprintf( TEXT("Directory not important\n"));
    			}
    			else 
    			{
    				myFileInfo mfi;
    				mfi.setFileName((wstring)findFileData.cFileName);
    				mfi.setFileType(findFileData.dwFileAttributes);
    				strList.push_back(mfi);
    				foundCount++;
    			}			
    		}while(FindNextFile(hFind, &findFileData));
    	FindClose( hFind);
     
    	for (list<myFileInfo>::iterator iter = strList.begin(); iter != strList.end(); iter++)
    	{
    		myFileInfo itString = (*iter);
     
    		for (UINT indCount = 0; indCount < Indent; indCount++)
    			_tprintf( TEXT("  "));
     
    		if (itString.getFileType() & FILE_ATTRIBUTE_DIRECTORY)
    		{
    			WCHAR newPath[MAX_PATH];
    			WCHAR newDest[MAX_PATH];
     
                hr = StringCchCopyW(newPath, ARRAYSIZE(newPath), srcPath);
                if(FAILED(hr))
                { return 1; }
    			hr = StringCchCatW(newPath, ARRAYSIZE(newPath), (STRSAFE_LPCWSTR) itString.getFileName().c_str());
                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), (STRSAFE_LPCWSTR) itString.getFileName().c_str());
                if(FAILED(hr))
                { return 1; }            
                hr = StringCchCatW(newDest, ARRAYSIZE(newDest), L"\\");
                if(FAILED(hr))
                { return 1; }
     
    			hr = CeCreateDirectory(newDest, NULL);
    			if( hr = 0 )
    			{ return 1; }
     
                FoundFile(newPath, newDest, Indent + 1);
    		}
    		else
    		{
    			WCHAR srcCopyFile[MAX_PATH];
    			WCHAR destCopyFile[MAX_PATH];
     
    			hr  = StringCchCopyW(srcCopyFile, ARRAYSIZE(srcCopyFile), srcPath);
    			if(FAILED(hr))
    			{ return 1; }
    			hr  = StringCchCatW(srcCopyFile, ARRAYSIZE(srcCopyFile), (STRSAFE_LPCWSTR) itString.getFileName().c_str());
    			if(FAILED(hr))
    			{ return 1; }
     
    			hr  = StringCchCopyW(destCopyFile, ARRAYSIZE(destCopyFile), destPath);
    			if(FAILED(hr))
    			{ return 1; }
    			hr  = StringCchCatW(destCopyFile, ARRAYSIZE(destCopyFile), (STRSAFE_LPCWSTR) itString.getFileName().c_str());
    			if(FAILED(hr))
    			{ return 1; }
     
    			FileCopy( srcCopyFile, destCopyFile);
    		}
    	}	
    	return 0;
    }
     
    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;
    }
    si jamais il y a plus simple, 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