Powershell版(ZipFileクラス利用サンプル) .zip ファイルを作成して抽出

 C#版『ZipFile クラスを使用して圧縮された .zip ファイルの作成と抽出を行う方法』をPowershell版にしたもの。この例では、フォルダーの内容を新しい .zip ファイルに圧縮し、その zip を新しいフォルダーに抽出します。サンプルを実行するには、プログラムのフォルダーに start フォルダーを作成し、圧縮するファイルをそこに置きます。

サンプル

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("")
view raw zipfilemake.ps1 hosted with ❤ by GitHub

引用元

ZipFile.ExtractToDirectory メソッド (System.IO.Compression) | Microsoft Docs

元にしたコード(C#版)

コメント

zh-CNenfrja
タイトルとURLをコピーしました