Too many zip entries?

Feb 3, 2012 at 10:41 PM

DNZ is great first of all!

using v1.9 Ionic.Zip.Reduced.dll

running on windows server 2003 R2 - SP2

When trying to zip a directory consisting of 288,782 files, I get the error code below.  The [old_files] variable is simply a generic List(of String) containing the file path(s) to all file(s) that are older than 6 months in the specified directory. I have yet to find anything pertaining to an upper bound on the number of entries within a zip in the documentation.  I don't get why the entries would be limited to a 16-bit value but there's a lot of things in life I don't understand.  I will continue to look into this and post what I get but any assistance would be greatly appreciated.

ERROR:

>[ERROR] Zipping process failed:
Ionic.Zip.ZipException: The number of entries is 65535 or greater. Consider setting the UseZip64WhenSaving property on the ZipFile instance.
   at Ionic.Zip.ZipFile.Save()
   at Ionic.Zip.ZipFile.Save(String fileName)
   at Archive_App_DNZ.Module1.zipper(List`1 old_files, String target_archive_dir)

VB (zipping part):

ZipFileToCreate = target_archive_dir & Replace(Date.Now.ToString.Substring(0, Date.Now.ToString.IndexOf(" ")), "/", "_") & ".zip"
Using zip As ZipFile = New ZipFile
     zip.AddFiles(old_files, "")
     zip.Save(ZipFileToCreate)
End Using

Feb 7, 2012 at 8:52 PM
Edited Feb 7, 2012 at 8:55 PM

based on the previous posted error, I presumed that the Save method produced this error b/c it was writing over 65,535 files to the created archive file at one time.  This led me to try and alter my code so that I'm not writing a large (>65535) number of files to the zip file at one time.  Instead, I am taking a subset of the [old_files] list and writing them incrementally; as in continue zipping 100 files at a time into a single zip file until all files are zipped.  the summarized VB code is below (insert code snippet isn't working):

 'Zips 65,535 files and creates initial instance of zip file
 Sub zipper(ByVal old_files As System.Collections.Generic.List(Of String), ByVal target_archive_dir As String)
        Dim ZipFileToCreate As String
        Dim temp_old_files As New System.Collections.Generic.List(Of String)
        Dim list_max As Integer
        Dim zip_count As Integer = 0

        Try
            If old_files.Count > 65535 Then
                list_max = 65535
            Else
                list_max = old_files.Count
            End If

            temp_old_files.AddRange(old_files.GetRange(0, list_max))
            old_files.RemoveRange(0, list_max)
            ZipFileToCreate = target_archive_dir & Replace(Date.Now.ToString.Substring(0, Date.Now.ToString.IndexOf(" ")), "/", "_") & ".zip"

            Using zip As ZipFile = New ZipFile
                zip.AddFiles(temp_old_files, "")
                zip.Save(ZipFileToCreate)
            End Using
            temp_old_files.Clear()

            If old_files.Count > 0 Then
                zip_count = list_max + zipper_add(old_files, ZipFileToCreate)
            Else
                zip_count = list_max
            End If

            log_text = log_text & vbTab & "> " & zip_count & " Files Archived." & vbCrLf

        Catch e As Exception
            log_text = log_text & vbCrLf & vbTab & ">[ERROR] Zipping process failed:" & vbCrLf & e.ToString()
            Console.WriteLine(">[ERROR] Zipping process failed: {0}", e.ToString())
        End Try

    End Sub

 'opens existing zip file and add up to 65,535 files into at a time
    Function zipper_add(ByVal old_files As System.Collections.Generic.List(Of String), ByVal existing_zip As String)
        Dim temp_old_files As New System.Collections.Generic.List(Of String)
        Dim list_max As Integer
        Dim zip_count As Integer = 0

        Try
            If old_files.Count > 65535 Then
                list_max = 65535
            Else
                list_max = old_files.Count
            End If

            temp_old_files.AddRange(old_files.GetRange(0, list_max))
            old_files.RemoveRange(0, list_max)

            Using zip As ZipFile = ZipFile.Read(existing_zip)
                zip.AddFiles(temp_old_files, "")
                zip.Save(existing_zip)
            End Using

            temp_old_files.Clear()

            If old_files.Count > 0 Then
                zip_count = list_max + zipper_add(old_files, existing_zip)
            Else
                zip_count = list_max
            End If

            Return zip_count
        Catch e As Exception
            log_text = log_text & vbCrLf & vbTab & ">[ERROR] Zipping process failed:" & vbCrLf & e.ToString()
            Console.WriteLine(">[ERROR] Zipping process failed: {0}", e.ToString())
        End Try

    End Function

It could be "cleaner" i know but I'll worry about that when I figure out the solution to my problem. The upper bound in the above code is 65,535 but I tried 100;1,000;and 60,000 and all results were the same. Anyway, this method results in the EXACT same error as before.  This leads me to conclude that the Save method gets ticked off when trying to write any zip file that contains >65,535 files.  Is this normal or am I not considering something? For the time being I may just have to create multiple zip files for zipping folders that contain over 65,535 files in them.  To be continued...

Feb 8, 2012 at 10:06 PM

OH THE PAIN OF IGNORANCE!!!!

I figued out my problem.  Turns out that if I would have actually read the "Create a Zip archive that uses ZIP64 extensions..." paragraph on the examples page all of this could have been avoided.  I honestly just skimmed over it thinking "64" anything doesn't pertain to me b/c I'm on a 32-bit machine...oh, I couldn't have been more wrong and more ignorant about zip files! I'm about to test my application using the UseZip64WhenSaving property set to "asnecessary" and go from there... hopefully my post sheds some light on the zip file limitations to others who need to be slapped in the face by ignorance! On my way...