ECode IoUtils::DeleteContents( /* [in] */ IFile* dir) { VALIDATE_NOT_NULL(dir) AutoPtr<ArrayOf<IFile*> > files; dir->ListFiles((ArrayOf<IFile*>**)&files); Boolean result; if (files != NULL) { Boolean isDir; for (Int32 i = 0; i < files->GetLength(); ++i) { IFile* file = (*files)[i]; if (file->IsDirectory(&isDir), isDir) { DeleteContents(file); } file->Delete(&result); } } return NOERROR; }
Boolean FileUtils::DeleteContents( /* [in] */ IFile* dir) { AutoPtr<ArrayOf<IFile*> > files; dir->ListFiles((ArrayOf<IFile*>**)&files); Boolean success = TRUE; if (files != NULL) { Boolean bval; for (Int32 i = 0; i < files->GetLength(); ++i) { IFile* file = (*files)[i]; if (file->IsDirectory(&bval), bval) { success &= DeleteContents(file); } if (file->Delete(&bval), !bval) { //Log.w(TAG, "Failed to delete " + file); success = FALSE; } } } return success; }