Breaking Zip files based on File Size?

Apr 7 2005 11:31 AM
Newbie with C# looking for some help. I have an application that compares filenames within a file to a folder with the actual files. If the filenames in the file matches the actual name of the files in the folder, the files within the folder gets added to a zip file. My problem is that sometimes these zip files get to large. While the zip file is getting created, is there a way to check the file size and stop at a certain size? And then start a new file from where the first left off? Thanks in advance...here is some of the code. const int bufsize = 1000; long numBytes = 0; string [] files = Directory.GetFiles(folder, "*.pdf"); ZipOutputStream writer = new ZipOutputStream(File.Create(zipFilename)); int myCounter = 0; foreach (string filename in files) { FileStream fs = File.OpenRead(filename); int pos = filename.LastIndexOf(@"\"); string justName = (pos >=0) ? filename.Substring(pos + 1) : filename; //Compares the file names in the PDFSort_Index file to the acutal PDF names in the directory foreach (string sOutput in arrText) { if (sOutput == justName) { Console.WriteLine("zipping: " + justName); ZipEntry entry = new ZipEntry(justName); entry.DateTime = DateTime.Now; writer.PutNextEntry(entry); byte[] buffer = new byte[bufsize]; int count; myCounter++; while ((count = fs.Read(buffer, 0, bufsize)) > 0) { numBytes += count; writer.Write(buffer, 0, count); } } } } Console.WriteLine( "Total Files Zipped: " + myCounter ); writer.Finish(); writer.Close(); }