System.IO.Compression and ZipFile - extract and overwrite

.net, compression, system.io.compression, vb.net, zip

Solution

Use ExtractToFile with overwrite as true to overwrite an existing file that has the same name as the destination file

    Dim zipPath As String = "c:\example\start.zip" 
    Dim extractPath As String = "c:\example\extract" 

    Using archive As ZipArchive = ZipFile.OpenRead(zipPath)
        For Each entry As ZipArchiveEntry In archive.Entries
            entry.ExtractToFile(Path.Combine(extractPath, entry.FullName), True)
        Next 
    End Using 

Problem

I'm using the standard VB.NET libraries for extracting and compressing files. It works as well but the problem comes when I have to extract and files exist already. Code I use Imports: ``` Imports System.IO.Compression ``` Method I call when it crashes ``` ZipFile.ExtractToDirectory(archivedir, BaseDir) ``` archivedir and BaseDir are set as well, in fact it works if there are no files to overwrite. The problem comes exactly when there are. How can I overwrite files in extraction without use thirdy-part libraries? (Note I'm using as Reference System.IO.Compression and System.IO.Compression.Filesystem) Since the files go in multiple folders having already existent files I'd avoid manual ``` IO.File.Delete(..) ```

Original source