Monday, February 1, 2010

How To Zip The Folder using VB script

Option Explicit

Dim MySource, MyTarget, MyHex, MyBinary, i
Dim oShell, oCTF
Dim oFileSys
dim winShell
Const cstrApp = "Zip It"
MySource = InputBox("Enter path to folder to zip (Ex:D:\xyzfolder)", cstrApp ) 'Example :"D:\test\"
MyTarget = InputBox("Enter path and name of Zip file (Ex:D:\", cstrApp)'"D:\"

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

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
Set oCTF = Nothing

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


'Follow these steps only if you're receiving the 800A01AD error for Wscript.Shell component. For any other ActiveX object, the following steps does not apply:
'Click Start, Run and type:
' * regsvr32 wshom.ocx
' * regsvr32 scrrun.dll

Creative Commons License
Disclaimers:We have tried hard to provide accurate information, as a user, you agree that you bear sole responsibility for your own decisions to use any programs, documents, source code, tips, articles or any other information provided on this Blog.