Index: apps/gdal_translate.cpp =================================================================== --- apps/gdal_translate.cpp (revision 26089) +++ apps/gdal_translate.cpp (working copy) @@ -713,6 +713,25 @@ char** papszDupArgv = CSLDuplicate(argv); int nRet = 0; + CPLString osPath = CPLGetPath(pszDest); + CPLString osBasename = CPLGetBasename(pszDest); + CPLString osExtension = CPLGetExtension(pszDest); + CPLString osTemp; + + const char* pszFormat = NULL; + if ( CSLCount(papszSubdatasets)/2 < 10 ) + { + pszFormat = "%s_%d"; + } + else if ( CSLCount(papszSubdatasets)/2 < 100 ) + { + pszFormat = "%s_%002d"; + } + else + { + pszFormat = "%s_%003d"; + } + CPLFree(papszDupArgv[iDstFileArg]); papszDupArgv[iDstFileArg] = pszSubDest; bSubCall = TRUE; @@ -720,13 +739,15 @@ { CPLFree(papszDupArgv[iSrcFileArg]); papszDupArgv[iSrcFileArg] = CPLStrdup(strstr(papszSubdatasets[i],"=")+1); - sprintf( pszSubDest, "%s%d", pszDest, i/2 + 1 ); + osTemp = CPLSPrintf( pszFormat, osBasename.c_str(), i/2 + 1 ); + osTemp = CPLFormFilename( osPath, osTemp, osExtension ); + strcpy( pszSubDest, osTemp.c_str() ); nRet = ProxyMain( argc, papszDupArgv ); if (nRet != 0) break; } CSLDestroy(papszDupArgv); - + bSubCall = bOldSubCall; CSLDestroy(argv);