0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

CドライブにあるZIPファイルをDドライブに解凍するバッチファイル

Posted at

:: PowerShell のコマンドを呼び出して解凍する。
:: 解凍先フォルダが存在しない場合は新たに作成してくれる。
:: パスワード付ZIPは標準コマンドでは解凍できない(7zipなどを使う必要がある)。

ExpandZip.bat
@echo off

:: 解凍するZIPファイル
set zipPath=C:\temp\hogehoge.zip

:: ファイル名(拡張子除く)取り出し(解凍先フォルダ名にするため)
for %%F in (%zipPath%) do (
    set BASE_NAME=%%~nF
)

:: 解凍先フォルダ(フォルダは勝手に作ってくれる)
set expandPath=D:\temp\%BASE_NAME%

:: PowerShellのコマンドで解凍 ※[-Force]上書き
powershell Expand-Archive -Path %zipPath% -DestinationPath %expandPath% -Force

:: 解凍先を指定しなかった場合は、
:: カレントディレクトリ(このバッチファイルのある場所)に
:: ZIPファイルと同じ名前のフォルダで解凍される。
:: powershell Expand-Archive -Path %zipPath% -Force

:: 実行結果を確認
if %errorlevel% == 0 (
    echo 正常終了しました。戻り値:%errorlevel%
) else (
    echo 異常終了しました。戻り値:%errorlevel%
)

pause

<参考サイト>
【バッチファイル】ZIPファイルを解凍(展開)する

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?