This method compresses an entire directory structure into a .ZIP file. The only problem with that code is whenever there is an empty directory, this generates an error:
Public Function ZipDirectory() As Boolean
Dim llSuccess As Boolean = False
Dim loByte(21) As Byte
Dim loDestinationFolder As Shell32.Folder
Dim loFolderItems As Shell32.FolderItems
Dim loShellClass As Shell32.ShellClass = New Shell32.ShellClass
Dim loSourceFolder As Shell32.Folder
lError = False
cError = ""
Try
loByte(0) = 80 : loByte(1) = 75 : loByte(2) = 5 : loByte(3) = 6
File.WriteAllBytes(cDestinationFile, loByte)
loSourceFolder = loShellClass.NameSpace(cSourceFolder)
loDestinationFolder = loShellClass.NameSpace(cDestinationFile)
loFolderItems = loSourceFolder.Items
loDestinationFolder.CopyHere(loFolderItems, 20)
llSuccess = True
Catch loError As Exception
lError = True
cError = loError.Message
End Try
Return llSuccess
End Function
The Shell classes seems to be quite sensitive about that. Anyone have found a workaround for that?