Extract folder from a .zip file

Asked by At

I want to download a folder using a script, but I can't upload folders, so i decided to upload a .zip file.

The problem is that I want to extract the folder from the .zip file using a .

2 Answers

Flash Thunder On

In older PowerShell versions:

Add-Type -AssemblyName System.IO.Compression.FileSystem
[System.IO.Compression.ZipFile]::ExtractToDirectory("C:\file.zip", "C:\output")

Please note that you got to have .NET 4.5+ installed and it will NOT overwrite existing files (will throw an error if file exists).

In PowerShell v5+ you could simply use:

Expand-Archive C:\file.zip -DestinationPath C:\output

You can use relative paths in here as well.

js2010 On

Expand-archive is very basic. I'm not above using the command line version of 7zip, like for extracting specific folders. All you need is 7z.exe and 7z.dll.