0

So I've been using the DotNetZip Library for some time now, and it works pretty well, up until yesterday when I maxed out the zipfile size. On any given day, I need to zip PDFs and transfer them to an SFTP site, that only accepts zip files. The amount of PDFs range from a couple hundred, a couple thousand to well over 10K. I had about 24K PDFs yesterday when the DotNetZip process broke. There is a way to split the zipfiles using the DotNetZip library but for some reason, the system that is being used on the SFTP server cant handle zipfiles that are split.

What's the best way to grab say 5K (or any other set amount of files), zip, delete those files and grab another 5K, zip, delete and repeat the process until all files are zipped?

Here is my current code of the zip process...

        Dim PathToPDFs As String = "C:\Temp" 'PDF LOCATION
        Using Zip As ZipFile = New ZipFile()
            Zip.AddSelectedFiles("(name = *.pdf)", PathToPDFs, "", True)
            Zip.CompressionMethod = CompressionMethod.Deflate
            Zip.CompressionLevel = Ionic.Zlib.CompressionLevel.BestCompression
            Zip.Save("C:\Temp\Zipfile.zip")
        End Using
Muhnamana
  • 1,014
  • 13
  • 34
  • 57
  • Off topic perhaps, but why would you need to zip PDF files? They are compressed anyway, so you won't get much space saved. – Victor Zakharov Feb 05 '13 at 15:24
  • Well apparently this SFTP site I'm uploading to only accepts zip files. There is an automated process on the other end that will extact those PDFs. – Muhnamana Dec 17 '13 at 15:24

1 Answers1

0

Try enumerating through all files first, getting a list of FileInfo, then going through them in a loop, and creating ZIP files every 5K (or whichever your batch size is). You don't need to delete anything, just keep a batch id in memory, so your zip file names would derive from that (i.e. pdf_batch_01.zip).

So when your batch size is reached you would do Save and create a new ZipFile, and keep adding files in the loop. Don't forget to also "commit" at last file (last batch would most likely be incomplete). To sum up, you "commit" when batch size is reached OR processing last entry (a varitation of i=FileCount-1).

Victor Zakharov
  • 25,801
  • 18
  • 85
  • 151