Private Sub ComprimiAllFileZip(ByVal Directory As String, ByVal zipFileToCreate As String, Optional ByVal Password As String = Nothing)
Dim DirecotryName As String = Path.GetFileName(Directory)
Using zip As New ZipFile()
If (Password IsNot Nothing) Then
zip.Password = Password
End If
'zip.AddDirectory(@"MyDocuments\ProjectX", "ProjectX");
zip.AddDirectory(Directory, DirecotryName)
zip.Comment = "Qursto file è stato creato il " & System.DateTime.Now.ToString("G")
zip.CompressionMethod = CompressionMethod.BZip2
zip.Save(zipFileToCreate)
End Using
End Sub
Private Sub EstrarreAllFileZip(ByVal ExistingZipFile As String, ByVal BaseDirectory As String, Optional ByVal Password As String = Nothing)
Using zip As ZipFile = ZipFile.Read(ExistingZipFile)
For Each e As ZipEntry In zip
If Password IsNot Nothing Then
e.ExtractWithPassword(BaseDirectory, Password)
Else
e.CompressionMethod = CompressionMethod.BZip2
e.Extract(BaseDirectory, ExtractExistingFileAction.OverwriteSilently)
End If
Next
End Using
End Sub