System.IO.Compression和ZipFile

编程入门 行业动态 更新时间:2024-10-20 11:43:58
本文介绍了System.IO.Compression和ZipFile-提取并覆盖的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在使用标准的VB.NET库提取和压缩文件。它也可以正常工作,但是问题出在我必须提取文件并且文件已经存在的时候。

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.

我使用的代码

导入:

Imports System.IO.Compression

崩溃时我调用的方法

ZipFile.ExtractToDirectory(archivedir, BaseDir)

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?

(请注意,我正在使用System.IO.Compression和System.IO.Compression.Filesystem作为参考)

(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(..)

推荐答案

使用 ExtractToFile ,如果覆盖为true,则将覆盖与目标文件同名的现有文件

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

更多推荐

System.IO.Compression和ZipFile

本文发布于:2023-11-09 20:43:35,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1573390.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:IO   System   ZipFile   Compression

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!