'Unzipping a GZip with PowerShell works but can I extract directly to file?
Internet is an amazing place to be, I found this code that allows me to inflate a tar.gz file to .tar:
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 "C:\temp\maxmind\temp.tar.gz" "C:\temp\maxmind\temp.tar"
Now I have a .tar file in my hands. but how can I open that?
My goal is to extract directly from .tar.gz to file.
Solution 1:[1]
Get-ChildItem -Path $InputPath -Filter "*.tar.gz" |
Foreach-Object {
tar -xvzf $_.FullName -C $OutputPath
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | user1 |
