Creating .zip file with VBScript (internal Windows XP & up feature)

Sub CompressFolderToZip(ByVal FolderPath, ByVal ZipFilePath)

Dim ii, FSO, FilesInLogFolder
Const ForWriting = 2

‘ FolderToZip = “C:\BitmapCPCustomization”
‘ zipFile = “C:\”
FolderToZip = FolderPath
zipFile = ZipFilePath

set sa = CreateObject(“Shell.Application”)

Set FSO = CreateObject( “Scripting.FileSystemObject” )
FilesInLogFolder = FSO.GetFolder(FolderPath).Files.Count

‘ Create an empty ZIP file
Set objFSO = CreateObject( “Scripting.FileSystemObject” )
Set objTxt = objFSO.OpenTextFile( zipFile, ForWriting, True )
objTxt.Write “PK” & Chr(5) & Chr(6) & String( 18, Chr(0) )
Set objTxt = Nothing

Set zip= sa.NameSpace(zipFile)
Set Fol=sa.NameSpace(FolderToZip)
zip.CopyHere Fol.Items
‘WScript.Sleep 2000
wait 2

While Not sa.NameSpace(zipFile).Items.Count = FilesInLogFolder
Wait 10

End Sub


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s