Windows11ã§ã¯æ¨æºã§tarãã¡ã¤ã«ãgzipãã¡ã¤ã«ï¼gzãã¡ã¤ã«ï¼ã解åï¼å±éï¼ã§ããããã§ãããWindows10ã§ã¯ã§ãã¾ããã
PowerShellã使ã£ã¦gzipãã¡ã¤ã«ãå±éã§ããã¨ç¥ã£ãã®ã§ããã§ç´¹ä»ãã¦ããã¾ãã ãã®è¨äºã§ç´¹ä»ãã¦ããæ¹æ³ã¯ä¸ã®Microsoftã®è¨äºã«æ¸ããã¦ãããã®ã§ãã
Unzip GZ files using Powershell | Microsoft Learn
ãã®è¨äºã§ã®ç°å¢æ å ±ãå ã«ç¤ºãã¦ããã¾ãã
- Windows10 Version21H2
- PowerShell 5.1.19041.2364
åé¡
Windowsã§ã¯å§ç¸®ãã¡ã¤ã«ã¨ããã°zipãã¡ã¤ã«ã主æµã§ãããLinuxã§ã¯tarãã¡ã¤ã«ãtar.gzãã¡ã¤ã«ãgzipãã¡ã¤ã«ã使ãã¾ãã Windows10ã®æ¨æºæ©è½ã§ã¯zipãã¡ã¤ã«ãå±éã§ãããã®ã®ããã以å¤ã®å½¢å¼ã®ãã¡ã¤ã«ã¯ã§ãã¾ããã ï¼Lhaplusã7-zipãªã©ãã¤ã³ã¹ãã¼ã«ãããã¨ã§å±éãããã¨ã¯ã§ãã¾ããï¼
ãã ããPowerShellã§ã¯tarã³ãã³ããå©ç¨ã§ããããã
tarãã¡ã¤ã«ã¯tar -xvf sample.tar
ãtar.gzãã¡ã¤ã«ã¯tar -xvzf sample.tar.gz
ã®ããã«ããã°å±éå¯è½ã§ãã
ããããªãããgzipãã¡ã¤ã«ã¯tarã³ãã³ãã§ã¯å±éã§ãã¾ããã gzipãã¡ã¤ã«ã¯gzipã³ãã³ãã¾ãã¯gunzipã³ãã³ãã§å±éã§ãã¾ãããPowerShellã«ã¯å ¥ã£ã¦ãã¾ããã§ããã
解決æ¹æ³
Lhaplusã7-zipãªã©ã®ããªã¼ã½ãããã¤ã³ã¹ãã¼ã«ãããã¨ãªããPowerShellã§ã³ã¼ããæ¸ããã¨ã§gzipãã¡ã¤ã«ãå±éã§ãã¾ãã ã³ã¼ãã¯æåã«ç´¹ä»ããMicrosoftã®ãã¼ã¸ããæã£ã¦ãã¾ããã
Unzip GZ files using Powershell | Microsoft Learn
æé ã¯ä»¥ä¸ã®ã¨ããã§ãã
- PowerShellãèµ·åãã
- 以ä¸ã®ã³ãã³ããPowerShellã³ãã³ãã·ã§ã«ã«è²¼ãä»ãã
Function DeGZip-File { Param( $infile, $outfile = ($infile -replace '\.gz$','') ) $input = New-Object System.IO.FileStream $inFile, ([IO.FileMode]::Open), ([IO.FileAccess]::Read), ([IO.FileShare]::Read) $output = New-Object System.IO.FileStream $outFile, ([IO.FileMode]::Create), ([IO.FileAccess]::Write), ([IO.FileShare]::None) $gzipStream = New-Object System.IO.Compression.GzipStream $input, ([IO.Compression.CompressionMode]::Decompress) $buffer = New-Object byte[](1024) while($true){ $read = $gzipstream.Read($buffer, 0, 1024) if ($read -le 0){break} $output.Write($buffer, 0, $read) } $gzipStream.Close() $output.Close() $input.Close() }
- æé 2ã§ä½æãããã¡ã³ã¯ã·ã§ã³ã使ã£ã¦gzipãã¡ã¤ã«ãå±éãã
- å®è¡ä¾ï¼
DeGzip-File ".\mytestfile.txt.gz" ".\mytestfile.txt"
.\mytestfile.txt.gz
ãã¡ã¤ã«ã.\mytestfile.txt
ã¨ãã¦å±éããã¨ãããã¨ã«ãªãã¾ã
ps1ãã¡ã¤ã«ã¨batãã¡ã¤ã«ãä½ã£ã¦ä½¿ãããããã
å ã»ã©ã®ã³ã¼ããæ¯åPowerShellã«ã³ããããã®ã¯é¢åãããã®ã§ps1ãã¡ã¤ã«ã«ä¿åããbatãã¡ã¤ã«ããå¼ã³åºããããã«ãã¦ããã¾ãã
ç¨æãããã¡ã¤ã«ã¯2ã¤ã§ãã
DeGZip-File.ps1
: å è¿°ã®ã³ã¼ããå¤é¨ããå¼ã³åºããããã«ããPowerShellã¹ã¯ãªãããã¡ã¤ã«expand-gzip.bat
:DeGZip-File.ps1
ãå¼ã³åºãããã®batãã¡ã¤ã«
DeGZip-File.ps1
ãã¡ã¤ã«ã®å
容ã¯ä»¥ä¸ã®ããã«ãã¾ãã
Param($Arg1, $Arg2) Function DeGZip-File { Param( $infile, $outfile = ($infile -replace '\.gz$','') ) $input = New-Object System.IO.FileStream $inFile, ([IO.FileMode]::Open), ([IO.FileAccess]::Read), ([IO.FileShare]::Read) $output = New-Object System.IO.FileStream $outFile, ([IO.FileMode]::Create), ([IO.FileAccess]::Write), ([IO.FileShare]::None) $gzipStream = New-Object System.IO.Compression.GzipStream $input, ([IO.Compression.CompressionMode]::Decompress) $buffer = New-Object byte[](1024) while($true){ $read = $gzipstream.Read($buffer, 0, 1024) if ($read -le 0){break} $output.Write($buffer, 0, $read) } $gzipStream.Close() $output.Close() $input.Close() } DeGZip-File $Arg1 $Arg2
expand-gzip.bat
ãã¡ã¤ã«ã®å
容ã¯ä»¥ä¸ã®ããã«ãã¾ãï¼æåã³ã¼ãã¯S-JISã§ãï¼ã
@ECHO OFF ECHO å ¥åããããã¹ã®Gzipãã¡ã¤ã«ãå±éãã¾ã :INPUT_GZIP_PATH SET GZIP_PATH= SET /P GZIP_PATH="Gzipãã¡ã¤ã«ãã¹ãå ¥åãã¦ãã ãããï¼" IF "%GZIP_PATH%"=="" GOTO :INPUT_GZIP_PATH SET EXPAND_PATH= SET /P EXPAND_PATH="å±éå ãã¹ãå ¥åãã¦ãã ãããï¼çç¥å¯ãçç¥ããå ´åã«ã¯Gzipãã¡ã¤ã«ãã¹ã®æ«å°¾ .gz ãåé¤ãããã®ããã¹ã¨ãã¾ãï¼ï¼" ECHO GZipãã¡ã¤ã«ãã¹:[%GZIP_PATH%] å±éå ãã¹:[%EXPAND_PATH%] powershell -NoProfile -ExecutionPolicy Unrestricted -file .\DeGZip-File.ps1 "%GZIP_PATH%" "%EXPAND_PATH%" PAUSE EXIT
使ãæ¹ã¨ãã¦ã¯expand-gzip.bat
ãã¡ã¤ã«ãããã«ã¯ãªãã¯ããæ示ã®ã¨ããgzipãã¡ã¤ã«ã®ãã¹ã¨å±éå
ã®ãã¹ãå
¥åãã¾ãã
å®éã«å®è¡ããå¦çãå®äºããã¨ãã®ã³ãã³ãããã³ããã®æ§åã®ã¹ã¯ãªã¼ã³ã·ã§ãããè²¼ã£ã¦ããã¾ãï¼ã¡ãã£ã¨ããµã¤ã¯ã§ãããããï¼ãæå®ããå±éå
ãã¹ã«ãã¡ã¤ã«ãå±éããã¦ãããã¨ã確èªãã¦ãã ããã
ãããã«
gzipãã¡ã¤ã«ãPowerShellã ãã§å±éï¼è§£åï¼ããæ¹æ³ã¨ãããps1ãã¡ã¤ã«ã«ä¿åããbatãã¡ã¤ã«ãä»ãã¦ç°¡åã«å¼ã³åºããããã«ãã¾ããã
batãã¡ã¤ã«ã§ps1ãã¡ã¤ã«ã§ã®gzipãã¡ã¤ã«ã®å±éå¦çã®å¾ æ©ãã§ããã°ãã£ã¨ããæãã®batãã¡ã¤ã«ã«ãªã£ãã®ã§ãããããæ¹ãããããªãã£ãã®ã§ã¨ãããããããªæãã«ãªãã¾ããã
åè
- Unzip GZ files using Powershell | Microsoft Learn
- Download and extract gzip tar with PowerShell | Scattered Code
- ãææ°çãã¤ã³ã¹ãã¼ã«ãããã¨PowerShellèµ·åæã«å±ãããã¨ãã®å¯¾å¦æ³ï¼Tech TIPS - ï¼ IT
- PowerShellã®å§ãæ¹ï¼ã³ãã³ãã¨ããã°ã©ã 2éãã®å®è¡æ¹æ³ã¨ã¯
- PowerShellã®é¢æ° (Function) ã®ä½¿ãæ¹ | ãã¤ã¯ãã½ãå ããã°
- ããããã¡ã¤ã«ãã PowerShell ãå¼ã³åºãæ¹æ³ #PowerShell - Qiita
- ããã(bat)ã§ä»»æã®æåå ¥åå¾ ã¡âå ¥åâ確èªâå®äº ãä½æ