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
   |  
 //-----------------------------------------------------------------------------------
  /*Permet de copier un répertoire qui n'est pas vide fonction recursive
en C renvoit un bool pour savoir si cela c bien passé*/
bool  __fastcall CopyFilesFromDir( LPSTR pszPath,LPSTR pszPathDir)
{
        WIN32_FIND_DATA strcFindData;
        HANDLE          hFind;
        char            szSearchPath[MAX_PATH];
 
        strcpy( szSearchPath, pszPath );
        strcat( szSearchPath, "\\*" );
 
        hFind = FindFirstFile( szSearchPath, &strcFindData );
 
        if( hFind == INVALID_HANDLE_VALUE )
            return(FALSE);
 
        do {
            if( strcFindData.cFileName[0] == '.' &&
              strcFindData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY )
                continue;
 
            if( strcFindData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY ) {
                char    szNewPath[MAX_PATH];
                char    szNewPathDir[MAX_PATH];
 
                strcpy( szNewPath, pszPath );
                strcat( szNewPath, "\\" );
                strcat( szNewPath, strcFindData.cFileName );
 
                strcpy( szNewPathDir, pszPathDir );
                strcat( szNewPathDir, "\\" );
                strcat( szNewPathDir, strcFindData.cFileName );
                mkdir (szNewPathDir);
 
                if( ! CopyFilesFromDir( szNewPath,szNewPathDir ) ) {
                    return(FALSE);
                }
            } else {
                char    szFileName[MAX_PATH];
 
                strcpy( szFileName, pszPath );
                strcat( szFileName, "\\" );
                strcat( szFileName, strcFindData.cFileName );
 
                char    szFileNamesource[MAX_PATH];
                strcpy( szFileNamesource, pszPathDir );
                strcat( szFileNamesource, "\\" );
                strcat( szFileNamesource, strcFindData.cFileName );
                if( ! CopyFile( szFileName,szFileNamesource,FALSE ) ) {
                    return(FALSE);
                }
            }
        } while( FindNextFile( hFind, &strcFindData ) );
 
        FindClose( hFind );
 
        return(TRUE);
} | 
Partager