ZipFile クラス
定義
zip アーカイブの作成、抽出、および解凍の静的メソッドを提供します。Provides static methods for creating, extracting, and opening zip archives.
public ref class ZipFile abstract sealed
public static class ZipFile
type ZipFile = class
Public Class ZipFile
- 継承
-
ZipFile
注釈
重要
クラスを使用するには ZipFile 、プロジェクト内のアセンブリへの参照を追加する必要があります System.IO.Compression.FileSystem
。そうしないと、コンパイル時に次のエラーメッセージが表示されます。 ' ZipFile ' という名前は、現在のコンテキストに存在しません。To use the ZipFile class, you must add a reference to the System.IO.Compression.FileSystem
assembly in your project; otherwise, you'll get the following error message when trying to compile : The name 'ZipFile' does not exist in the current context. Visual Studio でプロジェクトに参照を追加する方法の詳細については、「 方法: 参照マネージャーを使用して参照を追加または削除する」を参照してください。For more information on how to add a reference to your project in Visual Studio, see How to: Add or Remove References By Using the Reference Manager.
Zip アーカイブとそのファイルを操作するためのメソッドは、3つのクラス ZipFile (、、および) に分散されてい ZipArchive ZipArchiveEntry ます。The methods for manipulating zip archives and their files are spread across three classes: ZipFile, ZipArchive and ZipArchiveEntry.
宛先...To... | 用途Use... |
---|---|
ディレクトリから zip アーカイブを作成するCreate a zip archive from a directory | ZipFile.CreateFromDirectory |
Zip アーカイブの内容をディレクトリに抽出するExtract the contents of a zip archive to a directory | ZipFile.ExtractToDirectory |
既存の zip アーカイブに新しいファイルを追加するAdd new files to an existing zip archive | ZipArchive.CreateEntry |
Zip アーカイブ内のファイルを取得するRetrieve a file in a zip archive | ZipArchive.GetEntry |
Zip アーカイブ内のすべてのファイルを取得するRetrieve all of the files in a zip archive | ZipArchive.Entries |
Zip アーカイブに含まれる個々のファイルへのストリームを開くにはTo open a stream to an individual file contained in a zip archive | ZipArchiveEntry.Open |
Zip アーカイブからファイルを削除するDelete a file from a zip archive | ZipArchiveEntry.Delete |
ZipFile ZipFileExtensions Windows 8.x ストアアプリでクラスまたはクラスを使用することはできません。You cannot use the ZipFile or ZipFileExtensions classes in Windows 8.x Store apps. Windows 8.x ストアアプリでは、次のクラスを使用して圧縮ファイルを操作する必要があります。In Windows 8.x Store apps, you should use the following classes to work with compressed files.
例Examples
この例では、クラスを使用して zip アーカイブを作成および抽出する方法を示し ZipFile ます。This example shows how to create and extract a zip archive by using the ZipFile class. フォルダーの内容を zip アーカイブに圧縮し、そのコンテンツを新しいフォルダーに抽出します。It compresses the contents of a folder into a zip archive, and then extracts that content to a new folder.
ヒント
ZipFile クラスを使用するには、プロジェクトの System.IO.Compression.FileSystem
アセンブリを参照する必要があります。To use the ZipFile class, you must reference the System.IO.Compression.FileSystem
assembly in your project.
using System;
using System.IO.Compression;
class Program
{
static void Main(string[] args)
{
string startPath = @".\start";
string zipPath = @".\result.zip";
string extractPath = @".\extract";
ZipFile.CreateFromDirectory(startPath, zipPath);
ZipFile.ExtractToDirectory(zipPath, extractPath);
}
}
Imports System.IO.Compression
Module Module1
Sub Main()
Dim startPath As String = ".\start"
Dim zipPath As String = ".\result.zip"
Dim extractPath As String = ".\extract"
ZipFile.CreateFromDirectory(startPath, zipPath)
ZipFile.ExtractToDirectory(zipPath, extractPath)
End Sub
End Module
メソッド
CreateFromDirectory(String, String) |
指定したディレクトリのファイルおよびディレクトリを含む zip アーカイブを作成します。Creates a zip archive that contains the files and directories from the specified directory. |
CreateFromDirectory(String, String, CompressionLevel, Boolean) |
指定したディレクトリのファイルおよびディレクトリを含む zip アーカイブを作成し、指定した圧縮レベルを使用し、オプションでベース ディレクトリを含みます。Creates a zip archive that contains the files and directories from the specified directory, uses the specified compression level, and optionally includes the base directory. |
CreateFromDirectory(String, String, CompressionLevel, Boolean, Encoding) |
指定したディレクトリのファイルおよびディレクトリを含む zip アーカイブを作成し、指定した圧縮レベルとエントリ名の文字エンコーディングを使用し、オプションでベース ディレクトリを含みます。Creates a zip archive that contains the files and directories from the specified directory, uses the specified compression level and character encoding for entry names, and optionally includes the base directory. |
ExtractToDirectory(String, String) |
指定した zip アーカイブのすべてのファイルをファイル システムのディレクトリに抽出します。Extracts all the files in the specified zip archive to a directory on the file system. |
ExtractToDirectory(String, String, Boolean) |
指定したアーカイブのすべてのファイルをファイル システムのディレクトリに抽出します。Extracts all of the files in the specified archive to a directory on the file system. |
ExtractToDirectory(String, String, Encoding) |
指定した zip アーカイブのすべてのファイルをファイル システムのディレクトリに抽出し、エントリ名に指定した文字エンコーディングを使用します。Extracts all the files in the specified zip archive to a directory on the file system and uses the specified character encoding for entry names. |
ExtractToDirectory(String, String, Encoding, Boolean) |
指定したアーカイブのすべてのファイルをファイル システムのディレクトリに抽出します。Extracts all of the files in the specified archive to a directory on the file system. |
Open(String, ZipArchiveMode) |
指定したパスとモードで zip アーカイブを開きます。Opens a zip archive at the specified path and in the specified mode. |
Open(String, ZipArchiveMode, Encoding) |
指定されたモードで、エントリ名に指定された文字エンコーディングを使用して指定されたパスの zip のアーカイブを開きます。Opens a zip archive at the specified path, in the specified mode, and by using the specified character encoding for entry names. |
OpenRead(String) |
指定されたパスで読み取りのための zip のアーカイブを開きます。Opens a zip archive for reading at the specified path. |