用windows bat脚本解压.tar.gz
时间: 2023-12-13 20:33:03 浏览: 166
以下是用Windows bat脚本解压.tar.gz的方法:
```bat
@echo off
setlocal enabledelayedexpansion
set "source_file=example.tar.gz"
set "destination_folder=example"
if not exist "%destination_folder%" mkdir "%destination_folder%"
for /f "tokens=1,2,*" %%a in ('powershell -command "(Get-Content '%source_file%' -Encoding Byte -TotalCount 2)[0..1] -join ''"') do set /a "header_size=%%a + (%%b * 256) + (%%c * 65536) + 1"
powershell -command "$stream = New-Object IO.FileStream('%source_file%', 'Open', 'Read', 'Read'); $stream.Seek(%header_size%, 'Begin') ; $gzip = New-Object IO.Compression.GzipStream($stream, [IO.Compression.CompressionMode]::Decompress); $dest = New-Object IO.FileStream('%destination_folder%\example.tar', 'Create', 'Write', 'Read'); $gzip.CopyTo($dest); $dest.Close(); $gzip.Close(); $stream.Close()"
cd "%destination_folder%"
tar -xvf example.tar
del example.tar
```
请注意,这个脚本假设你已经安装了tar命令行工具。如果你没有安装,你需要先安装tar工具才能使用这个脚本。