Hello so I have searched for this a long time allready and havent found anything about this. I search all the folders in the given folder and create an entry in the ziparchive for each file. It is needed that i keep the fodler structure. This is what i have come up with for now.
Imports System.IO
Imports System.IO.Compression
'a list of folders I want to zip. These are all located in the testfolder.
Public Shared ListofBackupFolders As New List(Of String) From {"SDK", "Programms", "Application", "Office", "Reports", "UserSettings", "de", "Intrastat", "XSD"}
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
Dim d As New DirectoryInfo("c:\temp\testfolder")
Dim directories = d.GetDirectories("*")
File.Create("C:\temp\test.zip").Close()
For Each directory In directories
'Only searches the Folders I selecten in the list
If ListofBackupFolders.Contains(directory.Name) Then
SearchFolder(directory.FullName)
End If
Next
End Sub
Private Sub SearchFolder(path As String)
Dim dirInfo As New DirectoryInfo(path)
Dim subDirectories = dirInfo.GetDirectories("*")
If path.EndsWith("Application") Then
'>>> Some of the selected folders are in the Application folder
For Each subdirectory In subDirectories
If ListofBackupFolders.Contains(subdirectory.Name) Then
'recursion to get all the folders in the selected folder
SearchFolder(subdirectory.FullName)
End If
Next
Else
If subDirectories.Any Then
For Each subdirectory In subDirectories
'>>> recursion to get all the folders in the selected folder
SearchFolder(subdirectory.FullName)
Next
End If
End If
Dim files = dirInfo.GetFiles("*")
Using zipToOpen As FileStream = New FileStream("C:\temp\test.zip", FileMode.Open)
Using archive As ZipArchive = New ZipArchive(zipToOpen, ZipArchiveMode.Update)
Dim readmeEntry As ZipArchiveEntry
For Each file In files
'for every File in the folders it creates the path in the zip
Dim zipPath = file.FullName.Replace("C:\", "").Replace("\", "/")
readmeEntry = archive.CreateEntryFromFile(file.FullName, zipPath, CompressionLevel.Fastest)
Next
If Not subDirectories.Any AndAlso Not files.Any Then
'if there are no files in a folder i still want the folder in the zip
Dim folderPath = path.Replace("C:\", "").Replace("\", "/") & "/"
readmeEntry = archive.CreateEntry(folderPath)
End If
End Using
End Using
End Sub
Now the problem I have is that i havent found a way to split the zip after a given volume (example 200mb).
And a other thing I need is that i have a single file that is for example 2gb i have to split that one aswell. This is seperate from the other code.