Powershell에서 파일을 압축/압축 해제하는 방법은 무엇입니까?

Powershell에서 파일을 압축/압축 해제하는 방법은 무엇입니까?

PowerShell에서 파일(*.zip)을 압축/압축 해제하는 단일 라이너가 있나요?

답변1

DotNetZipPowerShell에서 이 작업을 수행할 수 있습니다. 한 줄로 된 내용은 아니지만 라이브러리를 사용하면 필요한 PowerShell 스크립트를 작성할 수 있습니다.

COM 인터페이스를 사용할 수도 있습니다.Windows PowerShell을 사용하여 파일을 압축한 후 Windows Vista 사이드바 가젯을 패키징합니다..

"zip powershell" 또는 "unzip powershell"을 검색해 보면 유용한 결과를 얻을 수도 있습니다.

답변2

이것이 외부 도구 없이 Powershell에서 순수하게 수행할 수 있는 방법입니다. 그러면 현재 작업 디렉터리에 test.zip이라는 파일의 압축이 풀립니다.

$shell_app=new-object -com shell.application
$filename = "test.zip"
$zip_file = $shell_app.namespace((Get-Location).Path + "\$filename")
$destination = $shell_app.namespace((Get-Location).Path)
$destination.Copyhere($zip_file.items())

답변3

이제 .NET Framework 4.5에는압축 파일다음과 같이 사용할 수 있는 클래스:

[System.Reflection.Assembly]::LoadWithPartialName('System.IO.Compression.FileSystem')
[System.IO.Compression.ZipFile]::ExtractToDirectory($sourceFile, $targetFolder)

답변4

확인해 보세요.PSCX(PowerShell 커뮤니티 확장)이를 위해 특별히 cmdlet이 있습니다.

관련 정보