如果文件存在,则解压缩并覆盖

时间:2013-10-14 09:12:15

标签: c# zip

我想要做的是将文件解压缩到现有目录中并覆盖旧文件(如果存在)。

我正在使用此命令解压缩文件:

ZipFile.ExtractToDirectory(path + file_name_zip, path);

1 个答案:

答案 0 :(得分:3)

使用ZipFileExtensions.ExtractToFile

Extracts an entry in the zip archive to a file, and optionally overwrites an existing file that has the same name.

foreach (ZipArchiveEntry entry in archive.Entries)
                {
                    if (entry.FullName.EndsWith(".txt", StringComparison.OrdinalIgnoreCase))
                    {
                        entry.ExtractToFile(Path.Combine(extractPath, entry.FullName), true);
                    }
                }