Discussion:
How to create ZIP Files from Command-Line via VBScript?
(too old to reply)
FB
2008-07-07 17:50:48 UTC
Permalink
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?
Wayne Tilton
2008-07-07 18:20:40 UTC
Permalink
Post by FB
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?
How about a free command line ZIP utility instead of WinZIP?

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

HTH,

Wayne Tilton
LJB
2008-07-07 18:52:48 UTC
Permalink
Post by FB
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?
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
2008-07-07 18:58:01 UTC
Permalink
Post by FB
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?
Here is some info you may find useful too
http://www.rondebruin.nl/windowsxpzip.htm
FB
2008-07-08 00:28:01 UTC
Permalink
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
Post by LJB
Post by FB
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?
Here is some info you may find useful too
http://www.rondebruin.nl/windowsxpzip.htm
FB
2008-07-08 00:30:02 UTC
Permalink
What´s the purpose of the Const MyDest = "C:\scratch"???
In any circunstances this line is used for something?
Post by LJB
Post by FB
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?
Here is some info you may find useful too
http://www.rondebruin.nl/windowsxpzip.htm
LJB
2008-07-08 12:21:10 UTC
Permalink
WhatŽs the purpose of the Const MyDest = "C:\scratch"???
In any circunstances this line is used for something?
Const MyDest = "C:\scratch" was something I used and forgot to remove before
sending the example.
Fahim28
2009-05-10 08:33:35 UTC
Permalink
Hi, Your script really helped me... But how can i use wild cards like i
want to add C:\*.id file to the created zip file how wud i do that n
this script
--
Fahim28
------------------------------------------------------------------------
Fahim28's Profile: http://forums.techarena.in/members/97528.htm
View this thread: http://forums.techarena.in/server-scripting/997520.htm

http://forums.techarena.in
dunwich
2009-06-06 22:46:32 UTC
Permalink
(duplicated post)
--
dunwich
------------------------------------------------------------------------
dunwich's Profile: http://forums.techarena.in/members/103867.htm
View this thread: http://forums.techarena.in/server-scripting/997520.htm

http://forums.techarena.in
Mark D. MacLachlan
2009-07-02 07:18:16 UTC
Permalink
Have a look near the end of this thread:
http://www.tek-tips.com/viewthread.cfm?qid=1231429. Sample code is
given that should help you.

Hope that helps,

Mark D. MacLachlan

FB
2008-07-07 20:52:02 UTC
Permalink
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")
============================================
Post by LJB
Post by FB
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?
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
Loading...