in reply to Re: Grouping files before zipping!
in thread Grouping files before zipping!

After some research on another way of doing this I found that it could be done using Archive::Zip. I have a sample code that does check the size of a zip before zipping all the files in a directory, it only needs to be implemented to build multiple zip files if the files size exceed the permitted volume. Anyone?
use strict; use warnings; use Archive::Zip qw/AZ_OK/; use File::Temp qw/tempfile/; use constant MB => 1024 * 1024; my $dir = '/allfiletozip/'; my @files = do { opendir my $fd, "$dir" or die $! or die $!; grep -f, map "$dir$_", readdir $fd; }; my $zip = Archive::Zip->new; my $total; my $limit = 50*MB; foreach my $file (@files) { my $temp = Archive::Zip->new; my $member = $temp->addFile($file); next unless $member->compressedSize; my $fh = tempfile(); $temp->writeToFileHandle($fh) == AZ_OK or die $!; $zip->addMember($member); $total += $member->compressedSize; die "$total bytes exceeds archive size limit" if $total > $limit; } print "Total archive size: $total bytes\n\n"; $zip->writeToFileNamed('zipped.zip') == AZ_OK or die $!;

Thanks!