Unplanned
Last Updated: 07 May 2021 09:36 by ADMIN
Fit2Page
Created on: 07 May 2021 09:25
Category: ZipLibrary
Type: Feature Request
2
ZipLibrary: Allow ZipFile.ExtractToDirectory() to overwrite existing files when extract ZIP

Currently, an exception is thrown when the file being unzipped already exists in the destination folder. Expose overload of the ExtractToDirectory() method allowing users to overwrite files.

Alternatively, the ZipArchiveEntry.ExtractToFile() method can be used:

using (ZipArchive source = ZipFile.Open(sourceFileName, ZipArchiveMode.Read, null))
{
    foreach (ZipArchiveEntry entry in source.Entries)
    {
        string fullPath = Path.GetFullPath(Path.Combine(destinationDirectory, entry.FullName));

        if (Path.GetFileName(fullPath).Length != 0)
        {
            Directory.CreateDirectory(Path.GetDirectoryName(fullPath));
            // The boolean parameter determines whether an existing file that has the same name as the destination file should be overwritten
            entry.ExtractToFile(fullPath, true);
        }
    }
}

0 comments