Creating a ZIP Archive
Posted by admin - May 15, 2008 Articles, QTips, Yaron Assa, ZIP 0 0 Views : 318 Receive Updates For This Category
Article Tools
- Print this page
- Add Comment
- Send to Friend
- Last Updated on :
Jul 16, 2011
Windows XP has a built-in ZIP mechanism integrated into its file-system. We can easily use this to create standard ZIP archives with only a few commands:
1: 'Variable Declaration
2: Dim sSourceFolder
3: Dim sArchiveFile
4:
5: Dim oShell
6: Dim oZIP
7: Dim oSourceFolder
8:
9: 'Variable Initalization
10: sSourceFolder = "C:\SomeFolder"
11: sArchiveFile = "C:\some.zip"
12: set oShell = CreateObject("Shell.Application")
13:
14: 'Create ZIP
15: Set oZIP= oShell.NameSpace(sArchiveFile)
16:
17: 'Get Source Folder
18: Set oSourceFolder=oShell.NameSpace(sSourceFolder)
19:
20: 'Add source items to ZIP
21: oZIP.CopyHere(oSourceFolder.Items)
Update: As some of you have remarked, the above code only works if there’s already an empty ZIP file in place. Well, no problem – just add this code after line 11:
1: 'Create an empty ZIP file
2: 'Insert after line 11 (when sArchiveFile is defined
3:
4: Dim oFSO
5: dim oFile
6:
7: Set oFSO = CreateObject( "Scripting.FileSystemObject" )
8: Set oFile = oFSO.OpenTextFile( sArchiveFile , ForWriting, True )
9: oFile.Write "PK" & Chr(5) & Chr(6) & String( 18, Chr(0) )
10: oFile.Close
11: Set oFile = Nothing
12: Set oFSO = Nothing


