Bonjour,
mon problème est le suivant, je voudrai copier un dossier et son contenu.
Le dossier source se trouve sur un PDA sous Windows Mobile et la cible sera sur pc.

je tien à dire que ce code est entierement de la récup, un mixe de 'ptree.cpp' qui affiche tout le contenu d'un dossier et 'pget.cpp' qui copie un fichier de WM>PC.

j'aurai besoin d'aide sur la focntion FoundFile et CopyFileWCE
le pb est que quand je rencontre un dossier le chemin doit changer.
exemple : c:\ ya des fichiers etc et il y a le dossier Windows
je rentre dans le dossier windows pour copier les fichiers mais je doit change le chemin de destination.

enfin bref vous avez compris. je ferais le programme qui réalise la copie dans le sens contraire a partir de sa.
Merci Merci Merci bien

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
#include <windows.h>
#include <tchar.h>
#include <stdio.h>
#include <string.h>
#include <rapi.h>
#include <strsafe.h>
 
#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];
 
int CopyFileWCE(LPCWSTR wszSrcFile, LPCWSTR wszDestFile)
{
	HANDLE hSrc, hDest;
    DWORD dwNumRead, dwNumWritten;
 
	hSrc = CeCreateFile(
                wszSrcFile,
                GENERIC_READ,
                FILE_SHARE_READ,
                NULL,
                OPEN_EXISTING,
                FILE_ATTRIBUTE_NORMAL,
                NULL);
    if (INVALID_HANDLE_VALUE == hSrc)
    {
        _tprintf( TEXT("Unable to open Windows CE file"));
        return 1;
    }
 
    hDest = CreateFile(
                wszDestFile,
                GENERIC_WRITE,
                FILE_SHARE_READ,
                NULL,
                CREATE_ALWAYS,
                FILE_ATTRIBUTE_NORMAL,
                NULL);
 
    if (INVALID_HANDLE_VALUE == hDest)
    {
        _tprintf( TEXT("Unable to open host/destination file"));
        return 1;
    }
#ifdef UNICODE
    wprintf( TEXT("Copying WCE:%s to %s\n"), wszSrcFile, wszDestFile);
#else
    printf( TEXT("Copying WCE:%S to %s\n"), tszSrcFile, wszDestFile);
#endif
 
    do
    {
        if (CeReadFile(
                hSrc,
                &Buffer,
                sizeof(Buffer),
                &dwNumRead,
                NULL))
        {
            if (!WriteFile(
                    hDest,
                    &Buffer,
                    dwNumRead,
                    &dwNumWritten,
                    NULL))
            {
                _tprintf( TEXT("Error !!! Writing hostfile"));
                CeCloseHandle( hSrc);
				CloseHandle (hDest);
            }
        }
        else
        {
            _tprintf( TEXT("Error !!! Reading Windows CE file"));
            CeCloseHandle( hSrc);
			CloseHandle (hDest);
        }
        _tprintf( TEXT("."));                                        
    } while (dwNumRead);
    _tprintf( TEXT("\n"));
 
	return 0;
 
}
 
int FoundFile(LPWSTR Path, LPWSTR destPath, UINT Indent)
{
	DWORD foundCount; // nombre de fichier trouver
	LPCE_FIND_DATA findDataArray; // tableau de structure contenant les infos des fichiers
	HRESULT hr;
 
	if(!CeFindAllFiles(wszSrcDir, 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)
        {
			//si c'est un dossier
            _tprintf( TEXT("[%s]\n"),findDataArray[i].cFileName);
            WCHAR newPath[MAX_PATH];
			WCHAR newDest[MAX_PATH];
            hr = StringCchCopyW(newPath, ARRAYSIZE(newPath), Path);
            if(FAILED(hr))
            {
                return 1;
            }
			hr = StringCchCopyW(newDest, ARRAYSIZE(newDest), destPath);
            if(FAILED(hr))
            {return 1;}
 
            hr = StringCchCatW(newPath, ARRAYSIZE(newPath), findDataArray[i].cFileName);
            if(FAILED(hr))
            {
                return 1;
            }            
            hr = StringCchCatW(newDest, ARRAYSIZE(newDest), findDataArray[i].cFileName);
            if(FAILED(hr))
            {return 1;}
 
            hr = StringCchCatW(newPath, ARRAYSIZE(newPath), L"\\");
            if(FAILED(hr))
            {
                return 1;
            }
            hr = StringCchCatW(newDest, ARRAYSIZE(newDest), L"\\");
            if(FAILED(hr))
            {return 1;}
 
            FoundFile(newPath, newDest, Indent + 1);
        }
        else
        {	
			//si non
            _tprintf( TEXT("%s\n"),findDataArray[i].cFileName);
			CopyFileWCE(findDataArray[i], newDest);
        }
    }
 
	if (findDataArray)
    {
        RapiFreeBuffer(findDataArray);
    }
 
	return 0;
}
 
int main( int argc, char *argv[])
{
	HRESULT hRapiResult;
 
    int nResult;
 
    if (3 != argc)
    {
        _tprintf( TEXT("Syntax: PGET <wce file or directory> <host file or directory>\n"));
        return 1;
    }
 
#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 <wce file or directory>\n"));
        return 1;
    }
#else
    hr = StringCchCopy(wszSrcDir, ARRAYSIZE(wszSrcDir), argv[1]);
    if(FAILED(hr))
    {
		_tprintf( TEXT("Failed to convert input arguement <wce 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 <host file or directory>\n"));
        return 1;
    }
#else
    hr = StringCchCopy(wszDestDir, ARRAYSIZE(wszDestDir), argv[2]);
    if(FAILED(hr))
    {
		_tprintf( TEXT("Failed to convert input arguement <host 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); // appel fonction de traitement de fichier
 
	_tprintf( TEXT("Closing connection ..."));
    CeRapiUninit();
    _tprintf( TEXT("Done\n"));
 
	return 0;
}