VBScript/MS-DOS - Create Zip file in Win XP

G_M
G_M used Ask the Experts™
on
Hey guys,

I have been working on a script to back up data to a zip file for recovery later. Although I have found most of the information I need online, I am having an issue finding a complete answer to my problem.

I have this bit of code:

strFolderToZip = "C:\Test\" 
strZipFile = "C:\Test.zip" 

Set objShell = CreateObject("Shell.Application")
Set objZip = objShell.NameSpace(strZipFile)
Set objFolder = objShell.NameSpace(strFolderToZip)
objZip.CopyHere(objFolder.Items)
WScript.Sleep 2000

Open in new window


I like this bit of script. It is simple and adds files to an existing Zip file. The issue I am having is around creating the zip file to add the files to.

How do I create the zip file (using vbscript or MS-DOS) required before executing this piece of code without using a 3rd party tool?

Obviously the MS-DOS command would be passed by the VBScript, like:
objShell.Run "cmd /c mkdir " & """" & strZipFile & """"

Open in new window

Any help would be greatly appreciated.
Cheers
G_M
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Test your restores, not your backups...
Top Expert 2016
Commented:
G_M

Author

Commented:
This link enabled me to find the right answer.

Cheers bp
G_M

Author

Commented:
The code in that link wasn't exactly what I ended up using so here is my final product:

Set objFSO = CreateObject("Scripting.FileSystemObject")	
objFSO.CreateTextFile("C:\Test.zip")

strZipFile = "C:\Test.zip"
strFolderToZip = "C:\Test"

Set objShell = CreateObject("Shell.Application")
Set objZip = objShell.NameSpace(strZipFile)
Set objFolder = objShell.NameSpace(strFolderToZip)
objZip.CopyHere(objFolder.Items)
WScript.Sleep 5000

Open in new window


Cheers
G_M

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial