Command line unzipping windows

How can you zip or unzip from the script using ONLY Windows’ built-in capabilities?

In Windows you can zip some files by

right click → Send toCompressed (zipped) folder

And unzip by double clicking on the .zip file and extract the files.

Is there a way to apply those abilities from a script (.bat file) without the need to install any third-party software?

16 Answers 16

Back in 2013, that was not possible. Microsoft didn’t provide any executable for this.

From Windows 8 on, .NET Framework 4.5 is installed by default, with System.IO.Compression.ZipArchive and PowerShell available, one can write scripts to achieve this, see https://stackoverflow.com/a/26843122/71312

To expand upon Steven Penny’s PowerShell solution, you can incorporate it into a batch file by calling powershell.exe like this:

As Ivan Shilo said, this won’t work with PowerShell 2, it requires PowerShell 3 or greater and .NET Framework 4.

If you have Java installed, you can compress to a ZIP archive using the jar command:

c = Creates a new archive file.

M = Specifies that a manifest file should not be added to the archive.

f = Indicates target file name.

PowerShell 5.0

Create result.zip from the entire Test folder:

Extract the content of result.zip in the specified Test folder:

It isn’t exactly a ZIP, but the only way to compress a file using Windows tools is:

Advanced example (from ss64.com):

Using 7-Zip:

Zip: you have a folder foo , and want to zip it to myzip.zip

Unzip: you want to unzip it ( myzip.zip ) to current directory ( ./ )

100 machines in production which don’t have 7zip on them. To install that I would have to get the DevOps install it on all those machines and on all new machines that will be added to the clusters. I would rather avoid it. – Roee Gavirel May 9 ’16 at 5:27

I’ve been looking to answer this exact question and from my research, DiryBoy’s response seems to be accurate.

I found the compact.exe program compresses files but not to create a highly compressed file (or set of files). It is similar to the option you get when right clicking on a drive letter or partition in Windows. You get the option to do cleanup (remove temp files, etc) as well as compress files. The compressed files are still accessible but are just compressed to create space on a drive that is low on space.

I also found compress.exe which I did happen to have on my computer. It isn’t natively on most windows machines and is part of the 2003 resource kit. It does make a zipped file of sorts but it is really more similar to files from a windows setup disk (has the underscore as the last character of the file extension or name). And the extract.exe command extracts those files.

Читайте также:  Для чего нужна поддержка windows

However, the mantra is, if it can be done natively via the GUI then there is likely a way to do it via batch, .vbs, or some other type of script within the command line. Since windows has had the ‘send to’ option to create a zip file, I knew there had to be a way to do it via command line and I found some options.

Here is a great link that shows how to zip a file using windows native commands.

I tested it with a directory containing multiple nested files and folders and it worked perfectly. Just follow the format of the command line.

There is also a way to unzip the files via command line which I found as well. One way, just brings open an explorer window showing what the content of the zipped file is. Some of these also use Java which isn’t necessarily native to windows but is so common that it nearly seems so.

Command line unzipping windows

Вопрос

Does Windows 7 come with a native uncompress (unzip) tool that can be run from the command-line?

I am looking for native uncompress solution so that users do not have to either provide a third-party Unzip tool or for me having to create a self-extraction file.

Thanks
Jeff in Seattle

Ответы

According to my search, if you want to unzip file using command line, additional software maybe needed. Here are more information:

Vivian Xing — MSFT

Все ответы

According to my search, if you want to unzip file using command line, additional software maybe needed. Here are more information:

Vivian Xing — MSFT

The stahlwordk unzip seems to be built for 1999 zip files and doesn’t work with a zip file I just created with windows 7, do you have a pointer to a working tool?

There’s a way to unzip with explorer in vbscript, but I’ve just started using 7-zip:

Keep 7z.exe and 7z.dll together.

There’s a way to unzip with explorer in vbscript, but I’ve just started using 7-zip:

Keep 7z.exe and 7z.dll together.

OK so an update, on the 7-zip download page (http://7-zip.org/download.html) they have a specific command line version (http://downloads.sourceforge.net/sevenzip/7za920.zip). It does not even contain a 7z.dll so I presume the poster above was jerry rigging the normal install version. The zip file contains 7za.exe and 7-zip.chm. The help files seems broken to me so I found the switches online, but I only could find them on a japanese website, but it is english:

Читайте также:  Как вызвать сенсорную клавиатуру windows 10

Examples

extracts all files from the archive archive.zip to the current directory.

extracts all *.cpp files from the archive archive.zip to c:\soft folder.

Find this post helpful? Does this post answer your question? Be sure to mark it appropriately to help others find answers to their searches.

download the unzip.exe

store it wherever you like, i put mine in the program files folder, but anywhere is fine

add its path to your enviroment variables

then you can cd to your zipfile in command line and type «unzip yourzipfile.zip»

it will unzip in the current directory.

did you ever get a way to do with natively with windows. I have the same issue only it’s not windows 7 it is windows 2003 server. I DO NOT have permission to install any kind of unzip utility on this server but I have an automated process that needs to unzip a file on a regular basis and the paperwork process to get permission to install winzip or other utility that can be called from command line will take weeks- if such a feature exists built in it would make a world of difference.

anyone know what command might possibly work to use the windows explorer extract feature via command line.

I did not. However, I am using the 7za.exe available from 7-zip. It is just an executable and does not need to be installed, so maybe that will get you around your software installation issues. http://www.7-zip.org/download.html I believe it is the command line version named «7-Zip Command Line Version».

I use it and there is nothing installed. Hope it helps.

Find this post helpful? Does this post answer your question? Be sure to mark it appropriately to help others find answers to their searches.

Command line unzipping windows

This forum has migrated to Microsoft Q&A. Visit Microsoft Q&A to post new questions.

Answered by:

Question

Does Windows 7 come with a native uncompress (unzip) tool that can be run from the command-line?

I am looking for native uncompress solution so that users do not have to either provide a third-party Unzip tool or for me having to create a self-extraction file.

Thanks
Jeff in Seattle

Answers

According to my search, if you want to unzip file using command line, additional software maybe needed. Here are more information:

Vivian Xing — MSFT

All replies

According to my search, if you want to unzip file using command line, additional software maybe needed. Here are more information:

Читайте также:  Reset windows with command prompt

Vivian Xing — MSFT

The stahlwordk unzip seems to be built for 1999 zip files and doesn’t work with a zip file I just created with windows 7, do you have a pointer to a working tool?

There’s a way to unzip with explorer in vbscript, but I’ve just started using 7-zip:

Keep 7z.exe and 7z.dll together.

There’s a way to unzip with explorer in vbscript, but I’ve just started using 7-zip:

Keep 7z.exe and 7z.dll together.

OK so an update, on the 7-zip download page (http://7-zip.org/download.html) they have a specific command line version (http://downloads.sourceforge.net/sevenzip/7za920.zip). It does not even contain a 7z.dll so I presume the poster above was jerry rigging the normal install version. The zip file contains 7za.exe and 7-zip.chm. The help files seems broken to me so I found the switches online, but I only could find them on a japanese website, but it is english:

Examples

extracts all files from the archive archive.zip to the current directory.

extracts all *.cpp files from the archive archive.zip to c:\soft folder.

Find this post helpful? Does this post answer your question? Be sure to mark it appropriately to help others find answers to their searches.

download the unzip.exe

store it wherever you like, i put mine in the program files folder, but anywhere is fine

add its path to your enviroment variables

then you can cd to your zipfile in command line and type «unzip yourzipfile.zip»

it will unzip in the current directory.

did you ever get a way to do with natively with windows. I have the same issue only it’s not windows 7 it is windows 2003 server. I DO NOT have permission to install any kind of unzip utility on this server but I have an automated process that needs to unzip a file on a regular basis and the paperwork process to get permission to install winzip or other utility that can be called from command line will take weeks- if such a feature exists built in it would make a world of difference.

anyone know what command might possibly work to use the windows explorer extract feature via command line.

I did not. However, I am using the 7za.exe available from 7-zip. It is just an executable and does not need to be installed, so maybe that will get you around your software installation issues. http://www.7-zip.org/download.html I believe it is the command line version named «7-Zip Command Line Version».

I use it and there is nothing installed. Hope it helps.

Find this post helpful? Does this post answer your question? Be sure to mark it appropriately to help others find answers to their searches.

Оцените статью