Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

is it possible to create a .zip file from a folder in the command line, I don't want to use any third party executable.

I was thinking something like 'send to compressed folder' but I don t know how to do it...

share|improve this question

migrated from stackoverflow.com Oct 20 '10 at 8:11

This question came from our site for professional and enthusiast programmers.

There's a tool in the Windows resource kit called compress.exe. –  ho1 Oct 20 '10 at 7:56
Here's a link to a ServerFault question that discusses just this: serverfault.com/questions/39071/… –  ho1 Oct 20 '10 at 7:57

5 Answers 5

I don't think there is a command line for ZIP files built in to Windows (Other than compress in Server 2003 Resource Kit). You'd have to use a third party. Everybody loves 7zip!

share|improve this answer

I've combined this script from several different sources to suit my needs better. Copy and paste the script into a file with the extension ".vbs". The script was originally made for Windows XP, but it also works in Windows 7 x64 Ultimate - no guarantee's if Windows will keep around the various Shell objects this uses.

Usage: in the run box or command line put-

"C:\zipper.vbs" "C:\folderToZip\" "C:\mynewzip.zip"

Path to script, source folder, zip file to make (include .zip at the end).

It won't copy empty folders so be careful.

Here is the vbs code ---

Set Args = Wscript.Arguments
source = Args(0)
target = Args(1)

' make sure source folder has \ at end
If Right(source, 1) <> "\" Then
    source = source & "\"
End If

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set zip = objFSO.OpenTextFile(target, 2, vbtrue)
' this is the header to designate a file as a zip
zip.Write "PK" & Chr(5) & Chr(6) & String( 18, Chr(0) )
Set zip = nothing

wscript.sleep 500

Set objApp = CreateObject( "Shell.Application" )
intSkipped = 0

' Loop over items within folder and use CopyHere to put them into the zip folder
For Each objItem in objApp.NameSpace( source ).Items
    If objItem.IsFolder Then
        Set objFolder = objFSO.GetFolder( objItem.Path )
        ' if this folder is empty, then skip it as it can't compress empty folders
        If objFolder.Files.Count + objFolder.SubFolders.Count = 0 Then
            intSkipped = intSkipped + 1
            objApp.NameSpace( target ).CopyHere objItem
        End If
        objApp.NameSpace( target ).CopyHere objItem
    End If

intSrcItems = objApp.NameSpace( source ).Items.Count
wscript.sleep 250

' delay until at least items at the top level are available
Do Until objApp.NameSpace( target ).Items.Count + intSkipped = intSrcItems
    wscript.sleep 200

Set objItem = nothing
Set objFolder = nothing
Set objApp = nothing
Set objFSO = nothing
share|improve this answer
Looks promising, but I got an "Object required: 'objApp.NameSpace(...)' error on line 16 –  pihentagy Nov 20 '12 at 8:55
I have the same problem. The above code doesn't work, or needs some extra stuff in the system the poster forgot to mention. –  Shaamaan Feb 1 '13 at 11:13
It uses WScript (vbs environment) and several Shell objects. All were installed by default in Windows XP (business?) and Win 7 Ultimate x64. Perhaps they are longer there for Win8? –  WSkid Feb 1 '13 at 18:25

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

Can you zip a file from the command prompt using ONLY Windows' built-in capability to zip files?

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.

Does Windows 7 have unzip at the command line installed by default?


share|improve this answer
You should include the instructions in your answer. If the links go stale, your answer will be worthless... –  MoonSire Nov 15 '13 at 6:50

I will post something related to WSkids answer as sadly i cannot use the comment function.

Using the CopyHere() method in VBS introduces several issues. One of these issues is that the method returns immediately while the copy process starts in background whereas multiple CopyHere() calls will interfere each other and the ZIP won't be created correctly. A wait loop is needed here to fix that. My wait loop is based on an answer to a similar issue posted here.

Here is an updated version which fixes the "Object required" error reported by pihentagy. It's a timing issue as the newly created ZIP file is included in the Items collection when the script is executed on fast machines.

set Args = WScript.Arguments
source = Args(0)
' remove trailing slashes as we add slashes when needed later
while Right(source, 1) = "\"
    source = Mid(source, 1, Len(source) - 1)

target = Args(1)

' create empty ZIP file
set fso = CreateObject("Scripting.FileSystemObject")
set zip = fso.OpenTextFile(target, 2, vbtrue)
' write ZIP header, this ensures that Windows recognizes the file as "ZIP Folder"
zip.Write "PK" & Chr(5) & Chr(6) & String(18, Chr(0))
set zip = nothing
set fso = nothing

' copy files to ZIP file
set app = CreateObject("Shell.Application")

set sourceFolderObj = app.NameSpace(source)
set targetFolderObj = app.NameSpace(target)

for each item in sourceFolderObj.Items
  itemPath = source & "\" & item.Name

  copyItem = false

  ' ZIP file is included in Items collection and is recognized as folder, thus skip it to avoid script errors
  if itemPath <> target then
    if item.IsFolder then
      if item.GetFolder.Items().Count = 0 then
        ' folder is empty, skip it as empty folders can't be compressed
        copyItem = true
      end if
      copyItem = true
    end if
  end if

  if copyItem then
    targetFolderObj.CopyHere item

    ' wait until the file appears in the ZIP file, 
    ' this is needed because CopyHere() returns immediately after starting an asynchronous copy process 
    ' (starting multiple asynchronous copy will not work as it causes error messages, an invalid ZIP file, ...)
    while (targetFolderObj.ParseName(item.Name) is nothing)
      WScript.Sleep 1
  end If

set targetFolderObj = nothing
set sourceFolderObj = nothing
set app = nothing
share|improve this answer

Here'a my attempt to summarize built-in capabilities windows for compression and uncompression - http://stackoverflow.com/questions/28043589/how-can-i-compres-zip-and-uncopress-unzip-files-and-folders-with-batch-f

with a few given solutions that should work on almost every windows machine.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.