static CPLErr OGRTABDriverDelete( const char *pszDataSource ) { GDALDataset* poDS = NULL; { // Make sure that the file opened by GDALOpenInfo is closed // when the object goes out of scope GDALOpenInfo oOpenInfo(pszDataSource, GA_ReadOnly); poDS = OGRTABDriverOpen(&oOpenInfo); } if( poDS == NULL ) return CE_Failure; char** papszFileList = poDS->GetFileList(); delete poDS; char** papszIter = papszFileList; while( papszIter && *papszIter ) { VSIUnlink( *papszIter ); papszIter ++; } CSLDestroy(papszFileList); VSIStatBufL sStatBuf; if( VSIStatL( pszDataSource, &sStatBuf ) == 0 && VSI_ISDIR(sStatBuf.st_mode) ) { VSIRmdir( pszDataSource ); } return CE_None; }
CPLErr GNMFileNetwork::Delete() { CPLErr eResult = GNMGenericNetwork::Delete(); if(eResult != CE_None) return eResult; // check if folder empty char **papszFiles = CPLReadDir( m_soNetworkFullName ); bool bIsEmpty = true; for(int i = 0; papszFiles[i] != NULL; ++i) { if( !(EQUAL(papszFiles[i], "..") || EQUAL(papszFiles[i], ".")) ) { bIsEmpty = false; break; } } CSLDestroy( papszFiles ); if( !bIsEmpty ) { return eResult; } return VSIRmdir(m_soNetworkFullName) == 0 ? CE_None : CE_Failure; }
OGRErr OGRGeoconceptDriver::DeleteDataSource( const char *pszDataSource ) { int iExt; VSIStatBuf sStatBuf; static const char *apszExtensions[] = { "gxt", "txt", "gct", "gcm", "gcr", NULL }; if( VSIStat( pszDataSource, &sStatBuf ) != 0 ) { CPLError( CE_Failure, CPLE_AppDefined, "%s does not appear to be a file or directory.", pszDataSource ); return OGRERR_FAILURE; } if( VSI_ISREG(sStatBuf.st_mode) && ( EQUAL(CPLGetExtension(pszDataSource),"gxt") || EQUAL(CPLGetExtension(pszDataSource),"txt") ) ) { for( iExt=0; apszExtensions[iExt] != NULL; iExt++ ) { const char *pszFile = CPLResetExtension(pszDataSource, apszExtensions[iExt] ); if( VSIStat( pszFile, &sStatBuf ) == 0 ) VSIUnlink( pszFile ); } } else if( VSI_ISDIR(sStatBuf.st_mode) ) { char **papszDirEntries = CPLReadDir( pszDataSource ); int iFile; for( iFile = 0; papszDirEntries != NULL && papszDirEntries[iFile] != NULL; iFile++ ) { if( CSLFindString( (char **) apszExtensions, CPLGetExtension(papszDirEntries[iFile])) != -1) { VSIUnlink( CPLFormFilename( pszDataSource, papszDirEntries[iFile], NULL ) ); } } CSLDestroy( papszDirEntries ); VSIRmdir( pszDataSource ); } return OGRERR_NONE; }