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...

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

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

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

2 Answers

I've combined this script from several different sources to suit my needs better...

Usage: in the run box put-

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

So 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 Ag=Wscript.Arguments
source = Ag(0)
target = Ag(1)
If Right(source, 1) <> "\" Then
    source = source & "\"
End If
Set fso = CreateObject("Scripting.FileSystemObject")
Set zip = fso.OpenTextFile(target, 2, vbtrue)
zip.Write "PK" & Chr(5) & Chr(6) & String( 18, Chr(0) )
Set fso = nothing
Set zip = nothing
wscript.sleep 500

Set objApp = CreateObject( "Shell.Application" )
intSkipped = 0
For Each objItem in objApp.NameSpace( source ).Items
    If objItem.IsFolder Then
        ' so, skip it to prevent an error message
        Set objFolder = objFSO.GetFolder( objItem.Path )
        If objFolder.Files.Count + objFolder.SubFolders.Count = 0 Then
            intSkipped = intSkipped + 1
        Else
            objApp.NameSpace( target ).CopyHere objItem
        End If
    Else
        objApp.NameSpace( target ).CopyHere objItem
    End If
Next
intSrcItems = objApp.NameSpace( source ).Items.Count
wscript.sleep 250
Do Until objApp.NameSpace( target ).Items.Count + intSkipped = intSrcItems
    wscript.sleep 200
Loop
Set objApp = nothing
link|improve this answer
feedback

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!

link|improve this answer
feedback

Your Answer

 
or
required, but never shown