voila mon petit bout de code qui copie tous les fichiers d'un repertoire(c:\t) vers un autre repertoire (c:\Zipper_Vtfw32) temporaire mais j'ai des erreurs lorsqu'il s'agit de fichier qui ne sont pas d'extension txt ou bin... si quelqu'un a une idee pour modifier cette fonction merci d'avance :)
void CTestDlg::OnOK()
{
// TODO: Add extra validation here
MyCopyDirectoryRec("c:\\t");
CDialog::OnOK();
}
void MyCopyDirectoryRec(CString rep)
{
char NewFileNameDebug[]={"c:\\Zipper_Vtfw32\"};
char FileNameDebug[MAX_PATH];
BOOL bErr = false;
unsigned int cpt = 0;
WIN32_FIND_DATA FindFileData;
strcpy(FileNameDebug,rep);
strcat(FileNameDebug,"\\*.*");
HANDLE hFind = FindFirstFile(FileNameDebug, &FindFileData);
if (hFind==INVALID_HANDLE_VALUE)
return;
DWORD a = 0;
while (cpt<5)//(a != ERROR_NO_MORE_FILES)
{
try
{
FindNextFile(hFind, &FindFileData);
}
catch( DWORD a )
{
a = GetLastError();
bErr = true;
}//end catch
Aucun besoin de try catch ici, API retourne toujours un code d'erreur mais n'en déclenche jamais, ça ne fait que grossir inutilement ton exe final et surtout le ralentir.
void MyCopyDirectoryRec(char *repsrc)
{
WIN32_FIND_DATA wfd;
HANDLE hfind;
char szsrc[264], *c;
char szdst[264], *d;
DWORD r;
r = strlen(repsrc);
if(strlen(repsrc) >= MAX_PATH) return: // PAS BON
c = szsrc + r; // c POINTE FIN DE DIR DESTINATION
// copie ton chemin dans szsrc
strcpy(szsrc, repsrc);
// ajoute un '\\' si n'y est pas et place pointer c juste derrière ce '\\' if(*(c-1) !'\\') *c++ '\\';
strcpy(c, "*.*");
hfind = FindFirstFile(buf, &wfd);
if(hfind == INVALID_HANDLE_VALUE) return;
strcpy(szdst, "d:\\mondossier\"); // A CHANGER
d = szdst + 14; // A CHANGER PAR LONGUEUR DOSSIER AU DESSUS