解压缩 C# 中的 Zip 文件

Muhammad Maisam Abbas 2023年12月11日
解压缩 C# 中的 Zip 文件

本教程将讨论在 C# 中解压缩文件的方法。

使用 C# 中的 ZipFile.ExtractToDirectory() 函数解压缩文件

ZipFile 类用于在 C# 中创建,打开和提取 zip 文件。Zipfile.ExtractToDirectory() 方法将 zip 文件从指定的源文件夹提取到目标文件夹。我们首先需要安装软件包 System.IO.Compression 才能使用此方法。要使此方法正常工作,文件扩展名必须为 .zip

using System;
using System.IO.Compression;

namespace unzip_file {
  class Program {
    static void Main(string[] args) {
      string zipFilePath = @"C:\File\milestone 19.zip";
      string extractionPath = @"C:\File";
      ZipFile.ExtractToDirectory(zipFilePath, extractionPath);
      Console.WriteLine("Extracted Successfully");
    }
  }
}

输出:

Extracted Successfully

在上面的代码中,我们使用 C# 中的 ZipFile.ExtractToDirectory() 函数将路径 C:\File 内的 zip 文件 milestone 19.zip 提取到路径 C:\File 内。

Muhammad Maisam Abbas avatar Muhammad Maisam Abbas avatar

Maisam is a highly skilled and motivated Data Scientist. He has over 4 years of experience with Python programming language. He loves solving complex problems and sharing his results on the internet.

LinkedIn

相关文章 - Csharp File