Active11 days ago
- Zip File Via Command Line Windows
- Windows Cmd Zip
- Zip Files Using Command Prompt Windows
- Split Zip File Command Line Windows
In Windows you can zip some files by
right click → Send to → Compressed (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?
Download the free Windows executables: (for Linux, see below) to extract zip files on the command line, download unzip.exe here. This file is a copy of the original Info-ZIP unzip.exe version 5.52, provided for free under the Info-ZIP license. Alternatively, you may download it via the original Info-ZIP website. I used the zip.exe and cywin1.dll (3mb) to satisfy the ZIP and usage is one line. From the zip itself of using some batch code. I know can use a php bancompile'd with argv and pass a file to it. 'A zip from windows command line' is an old science fiction movie, right? – erm3nda Dec 10 '13 at 6:59. This guide is an extension of a previous post, Automate Zipping Tasks using the Command-line Interface that explained the use of the command-line tools for two free compression utilities, IZArc and 7-Zip. The information in this guide was tested on a Windows PC running Vista. Thanks for the reminder about the native Windows COMPACT.EXE. With the files I have I see it compresses to a ratio of about 2.3:1; with 7ZIP creating a.ZIP file the ratio is about 6:1. So there's definitely a difference but it's something we may be able to live with.
Peter Mortensen14.5k1919 gold badges8989 silver badges118118 bronze badges
Roee GavirelRoee Gavirel11.8k1010 gold badges5050 silver badges7676 bronze badges
16 Answers
Back in 2013, that was not possible. Microsoft didn't provide any executable for this.
See this link for some VBS way to do this.https://superuser.com/questions/201371/create-zip-folder-from-the-command-line-windows
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, seehttps://stackoverflow.com/a/26843122/71312
Peter Mortensen14.5k1919 gold badges8989 silver badges118118 bronze badges
DiryboyDiryboy
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.
Jason DuffettJason Duffett3,10522 gold badges1919 silver badges2121 bronze badges
The sims 2 pc download. As of .NET 4.5, PowerShell can do this:
For the last two lines,
bar
and foo
can be replaced with the name you would like the folder to have, or whatever the name is of the preexisting folder. foo.zip
in both cases acts as the zip file either to save as or to unzip from.Steven PennySteven Penny
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.
Noam ManosNoam Manos6,93411 gold badge3838 silver badges4343 bronze badges
PowerShell 5.0
From
Microsoft.PowerShell.Archive
you can use:E.g.:
- Create
result.zip
from the entireTest
folder: - Extract the content of
result.zip
in the specifiedTest
folder:
37.5k2020 gold badges165165 silver badges154154 bronze badges
It isn't exactly a ZIP, but the only way to compress a file using Windows tools is:
To decompress:
Advanced example (from ss64.com):
More information: makecab, expand, makecab advanced uses
Peter Mortensen14.5k1919 gold badges8989 silver badges118118 bronze badges
Federico SantamorenaFederico Santamorena
Using 7-Zip:
Zip: you have a folder
foo
, and want to zip it to myzip.zip
Unzip: you want to unzip it (
phuclvmyzip.zip
) to current directory (./
)18.2k99 gold badges6161 silver badges267267 bronze badges
MonirMonir
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.
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.
Community♦
LostUserLostUser
You can use a VBScript script wrapped in a BAT file. This code works on a relative PATH.
There isn't any need for any third-party tools or dependencies. Just set
SOURCEDIR
and OUTPUTZIP
.Filename: ZipUp.bat
Zip File Via Command Line Windows
Example usage
Alternatively, you can parametrize this file by replacing the line
Peter MortensenCScript _zipup.vbs %SOURCEDIR% %OUTPUTZIP%
with CScript _zipup.vbs %1 %2
, in which case it can be even more easily called from by simply calling CALL ZipUp C:SourceDir C:Archive.zip
.14.5k1919 gold badges8989 silver badges118118 bronze badges
PodTech.ioPodTech.io
If you need to do this as part of a script then the best way is to use Java. Assuming the bin directory is in your path (in most cases), you can use the command line:
If Java is not on your path, reference it directly:
Peter Mortensen14.5k1919 gold badges8989 silver badges118118 bronze badges
eddyoceddyoc
Open source is your friend :-)
Here is the unzip: http://gnuwin32.sourceforge.net/packages/unzip.htm
There is a ZIP command as well:http://gnuwin32.sourceforge.net/packages/zip.htm
The binaries download is enough. Java latest version 2019.
Peter Mortensen14.5k1919 gold badges8989 silver badges118118 bronze badges
JanBorupJanBorupWindows Cmd Zip
3,91511 gold badge2424 silver badges1212 bronze badges
You say you're trying to do this without a third-party software. I'm not sure if you'd consider .NET 'third-party' software.
But you can create your own command line utility in .NET. It shouldn't require more than a few lines of code.
Peter Mortensen14.5k1919 gold badges8989 silver badges118118 bronze badges
NL3294NL3294
This is an updated version to the answer provided by @PodTech.io
This version has all of the vbs code correctly escaped in the batch file. It's also created into a sub-routine, which can be called with a single line from anywhere in your batch script:
fstefffsteff
I have a problem with all these solutions. They're not exactly the same, and they all create files that have a slight size difference compared to the
RMB --> send to --> compressed (zipped) folder
when made from the same source folder. The closest size-difference I have had is 300 KB difference (script > manual), made with:(Notice the -CompressionLevel. There are three possible values: Fastest, NoCompression & Optimal, (Default: Optimal))
I wanted to make a .bat file that should automatically compress a WordPress plugin folder I'm working on, into a .zip archive, so I can upload it into the WordPress site and test the plugin.
But for some reason it doesn't work with any of these automatic compressions, but it does work with the manual RMB compression, witch I find really strange.
And the script-generated .zip files actually break the WordPress plugins to the point where they can't be activated, and they can also not be deleted from inside WordPress. I have to SSH into the 'back side' of the server and delete the uploaded plugin files themselves, manually. While the manually RMB-generated files work normally.
Sebastian NorrSebastian Norr
Zip Files Using Command Prompt Windows
You can uncompress a zipped or native compressed Windows file by using the Expand command, e.g.
Peter Mortensen14.5k1919 gold badges8989 silver badges118118 bronze badges
LanceLance
Split Zip File Command Line Windows
To zip a file:
- -9 maximum compression
- -m delete original file after succesful compression
- -o set the modification date of zip file same as original file
- too bad one has to give it the name of desired zip file instead of it just adding .zip extension to the name ot the file to compress
1,77322 gold badges1111 silver badges2727 bronze badges
protected by Community♦Dec 8 '14 at 15:56
Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).
Would you like to answer one of these unanswered questions instead?
Would you like to answer one of these unanswered questions instead?