Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Creating a zip file without WINZIP

5,207 views
Skip to first unread message

PK

unread,
Apr 10, 2007, 9:58:17 AM4/10/07
to
I need a script that will create a zip file, and add files to it using
VBScript.

I can not use anything other than the built-in functions in Win XP SP2
(I can NOT use winzip or any other utility)

Anyone have anything on this?
Thanks

mr_unreliable

unread,
Apr 10, 2007, 12:19:27 PM4/10/07
to
As best I can recall, this has already been "asked-and-answered".

http://groups.google.com/advanced_group_search

cheers, jw
____________________________________________________________

You got questions? WE GOT ANSWERS!!! ..(but,
no guarantee the answers will be applicable to the questions)

Ayush

unread,
Apr 10, 2007, 12:27:11 PM4/10/07
to
[PK]s message :

This works:

FolderToZip = "C:\CygWin"
zipFile = "C:\some.zip"

set sa = CreateObject("Shell.Application")
Set zip= sa.NameSpace(zipFile)
Set Fol=sa.NameSpace(FolderToZip)
zip.CopyHere(Fol.Items)
WScript.Sleep 2000

Good Luck, Ayush.
--
Script Center-Script Repository : http://snipurl.com/Script_Repository

PK

unread,
Apr 10, 2007, 1:14:04 PM4/10/07
to
Ayush - thanks for the reply
I get an OBJECT REQUIRED 'ZIPp on line
zip.CopyHere(Fol.Items)

PK

unread,
Apr 10, 2007, 1:48:03 PM4/10/07
to
OK - I think I am almost there, but need a little help to bring it home...

I have a working script that will zip up an entire directory - how would i
modify this to zip a single file instead of the entire dir?

(watch for screen wrap)

Option Explicit
Const ForReading = 1, ForWriting = 2, ForAppending = 8

Dim MySource, MyTarget, MyZipName, MyHex, MyBinary, i
Dim oShell, oApp, oFolder, oCTF, oFile
Dim oFileSys

'MySource = "C:\DBMaintenance"
'MyTarget = "c:\SinkFolder.zip"

MySource = "C:\Documents and Settings\myusername\Desktop\ZIP
Test\FullFile.mdb"
MyTarget = "C:\Documents and Settings\myusername\Desktop\ZIP Test\Backup of
FullFile.zip"


MyHex = Array(80, 75, 5, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0)


For i = 0 To UBound(MyHex)
MyBinary = MyBinary & Chr(MyHex(i))
Next


Set oShell = CreateObject("WScript.Shell")
Set oFileSys = CreateObject("Scripting.FileSystemObject")


'Create the basis of a zip file.
Set oCTF = oFileSys.CreateTextFile(MyTarget, True)
oCTF.Write MyBinary
oCTF.Close
Set oCTF = Nothing


Set oApp = CreateObject("Shell.Application")


'Copy the files to the compressed folder
Set oFolder = oApp.NameSpace(MySource)
If Not oFolder Is Nothing Then
oApp.NameSpace(MyTarget).CopyHere oFolder.Items
End If


'Wait for compressing to begin, this was necessary on my machine
wScript.Sleep(5000)


'wait for lock to release
Set oFile = Nothing
On Error Resume Next
Do While (oFile Is Nothing)
'Attempt to open the file, this causes an Err 70, Permission Denied when the
file is already open
Set oFile = oFileSys.OpenTextFile(MyTarget, ForAppending, False)
If Err.number <> 0 then
Err.Clear
wScript.Sleep 3000
End If
Loop


Set oFile=Nothing
Set oFileSys=Nothing


PK

unread,
Apr 10, 2007, 2:26:01 PM4/10/07
to
GOT IT!

Here is my script which nicely creates a zip file and puts a file in it:

Option Explicit

Const FOF_SIMPLEPROGRESS = 256
Dim MySource, MyTarget, MyHex, MyBinary, i
Dim oShell, oCTF
Dim oFileSys
dim winShell

MySource = "C:\Documents and Settings\c9pxk1\Desktop\ZIP Test\FullFile.mdb"
MyTarget = "C:\Documents and Settings\c9pxk1\Desktop\ZIP Test\Backup of
FullFile.zip"

MyHex = Array(80, 75, 5, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0)

For i = 0 To UBound(MyHex)
MyBinary = MyBinary & Chr(MyHex(i))
Next

Set oShell = CreateObject("WScript.Shell")
Set oFileSys = CreateObject("Scripting.FileSystemObject")

'Create the basis of a zip file.
Set oCTF = oFileSys.CreateTextFile(MyTarget, True)
oCTF.Write MyBinary
oCTF.Close
Set oCTF = Nothing

'Add File to zip
set winShell = createObject("shell.application")
winShell.namespace(MyTarget).CopyHere MySource

wScript.Sleep(5000)

Frank B Smith

unread,
Jul 3, 2007, 3:50:05 PM7/3/07
to
What does the "myHex" do, or what is it for?
Tks


"PK" <P...@discussions.microsoft.com> wrote in message
news:DE13B047-1DB9-45E7...@microsoft.com...

Jimbo Jones

unread,
Jul 4, 2007, 7:26:29 AM7/4/07
to
this is a ridiculous attempt at writing PK to a text file, and then NOT
creating a zip file. i suggest the person that wrote this mess stick to perl
as its obvious thats where he comes from

"Frank B Smith" <fbs...@telus.net> wrote in message
news:8D1D8D1B-C001-4FF1...@microsoft.com...

Gottfried Mayer

unread,
Jul 4, 2007, 8:39:42 AM7/4/07
to
As far as I can see, it creates a valid (empty) ZIP File.

The script uses the abilities of Windows Explorer to handle "Zip
Folders" as "normal" Folders. It creates an empty Zip file and then
copies the Files to be compressed into the "Folder" (that's what the
Line [winShell.namespace(MyTarget).CopyHere MySource] does).

HTH
Gottfried


Frank B Smith schrieb:

himansh...@gmail.com

unread,
Jun 19, 2013, 7:33:26 AM6/19/13
to
Hi,

I am getting general run error on below line

winShell.namespace(MyTarget).CopyHere MySource

please help

Thanks
Himanshu

R.Wieser

unread,
Jun 19, 2013, 12:41:13 PM6/19/13
to
Have you checked if the Target ZIP file is actually created ?

I see you have a "ZIP Test" folder in the target path. If that one does not
exists you cannot create the "Backup of FullFile.zip" file either ...

Regards,
Rudy Wieser


-- Origional message:
<himansh...@gmail.com> schreef in berichtnieuws
a254f69e-a52b-406a...@googlegroups.com...
0 new messages