C#版『ZipFile クラスを使用して圧縮された .zip ファイルの作成と抽出を行う方法』をPowershell版にしたもの。この例では、フォルダーの内容を新しい .zip ファイルに圧縮し、その zip を新しいフォルダーに抽出します。サンプルを実行するには、プログラムのフォルダーに start フォルダーを作成し、圧縮するファイルをそこに置きます。
サンプル
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using namespace 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) | |
} | |
} | |
[Program]::Main("") |
引用元
ZipFile.ExtractToDirectory メソッド (System.IO.Compression) | Microsoft Docs
コメント