2

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.

Timo Kal
  • 21
  • 1
  • 4
  • Possible duplicate of [.Net library for split volume zip files?](https://stackoverflow.com/questions/6671811/net-library-for-split-volume-zip-files) – 41686d6564 stands w. Palestine Sep 21 '18 at 13:53
  • Same as above, GitHub Repository: [DotNetZip](https://github.com/haf/DotNetZip.Semverd). Available as NuGet Package as `DotNetZip 1.11.0.f7e1c3`. Includes .Net Standard, Android and IoS support. – Jimi Sep 21 '18 at 17:34
  • Do you mean you have an older version of Visual Studio or what else? You can always download the GitHub project and build it. – Jimi Sep 22 '18 at 20:44

0 Answers0