How to create ZIP Files from Command-Line via VBScript?

Discussion in 'Scripting' started by FB, Jul 7, 2008.

  1. FB

    FB Guest

    Ho can i create Zip Files via command-line?
    Can be done via WMI?

    I don´t wann use WinZIP COmmand Line Add-On, because it is not freeware

    Can i use VBScript to do that? Other "Lnaguage" maybe?
     
    FB, Jul 7, 2008
    #1
    1. Advertisements

  2. FB

    Wayne Tilton Guest

    How about a free command line ZIP utility instead of WinZIP?

    http://www.info-zip.org/

    HTH,

    Wayne Tilton
     
    Wayne Tilton, Jul 7, 2008
    #2
    1. Advertisements

  3. FB

    LJB Guest

    Since Windows already knows how to deal with zip files to some extent you
    might want to try the following. No external programs are needed. Believe it
    or not the wscript.sleep at the end is important to make this work
    correctly.

    Const FOF_CREATEPROGRESSDLG = &H0&

    Const MyZip = "C:\..\MyZipFile.zip"

    Const File1 = "C:\..\File1.txt"
    Const File2 = "C:\..\File2.txt"

    Const MyDest = "C:\scratch"

    '-------------- create empty zip file ---------

    'Create the basis of a zip file.
    CreateObject("Scripting.FileSystemObject") _
    .CreateTextFile(MyZip, True) _
    .Write "PK" & Chr(5) & Chr(6) & String(18, vbNullChar)


    '-------------- zip ---------------------------

    'get ready to add files to zip
    With CreateObject("Shell.Application")

    'add files
    .NameSpace(MyZip).CopyHere File1, FOF_CREATEPROGRESSDLG

    .NameSpace(MyZip).CopyHere File2

    End With
    wScript.Sleep 1000
     
    LJB, Jul 7, 2008
    #3
  4. FB

    LJB Guest

    LJB, Jul 7, 2008
    #4
  5. FB

    FB Guest

    Tanks, i´ll try it
    In this forum i found another Tip, in creating a Blank ZIP file with "PK"
    bytes and 17 bytes with CHR(0)

    I´ll try to see

    ============================================
    Set Ag=Wscript.Arguments
    username = CreateObject("Wscript.Shell").Environment("Process")("username")
    Set fso = CreateObject("Scripting.FileSystemObject")
    Set ts =
    fso_OpenTextFile(FilePath&"_forms\workforus\_uploads\"&"form_data.zip", 2,
    vbtrue)
    BlankZip = "PK" & Chr(5) & Chr(6)
    For x = 0 to 17
    BlankZip = BlankZip & Chr(0)
    Next
    ts.Write BlankZip
    set objFolder = nothing
    set objShell = nothing
    Set fso = nothing
    Set ts = nothing

    Set objShell = CreateObject("Shell.Application")
    Set WshShell = WScript.CreateObject("WScript.Shell")
    Set
    DestFldr=objShell.NameSpace(FilePath&"_forms\workforus\_uploads\"&"form_data.zip")
    Set SrcFldr=objShell.NameSpace(FilePath&"_forms\workforus\_csv")
    DestFldr.CopyHere (FilePath&"_forms\workforus\_csv")
    ============================================
     
    FB, Jul 7, 2008
    #5
  6. FB

    FB Guest

    It works great for small files, for large files i´ve added a Wscript.Echo
    (Modal Button, with OK) and ionly works if i click the OK button after the
    Zip proccess ( i can see a dialog box with a gauge indicating that the zipins
    in on the way

    Maybe it be necessary to use a higher number in the sleep directive
     
    FB, Jul 8, 2008
    #6
  7. FB

    FB Guest

    What´s the purpose of the Const MyDest = "C:\scratch"???
    In any circunstances this line is used for something?
     
    FB, Jul 8, 2008
    #7
  8. FB

    LJB Guest

    Const MyDest = "C:\scratch" was something I used and forgot to remove before
    sending the example.
     
    LJB, Jul 8, 2008
    #8
  9. Mark D. MacLachlan, Jul 2, 2009
    #9
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.