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 :
dans un premier temps j'ai supprimer le superflus de ma 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 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; }
code simplifier de la fonction "FoundFile" :Quand mon dossier est vide, il m'indique qu'il y a 2 fichiers.
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 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"
Merci
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; }
Partager