Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
Thanks!#!/usr/bin/perl -w use strict; use Archive::Zip qw/AZ_OK/; use File::Temp qw/tempfile/; use constant MB => 1024 * 1024; my $dir = qw( zip_this/); 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 = 5*MB; my $FileCount = 0; 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; my $new_total; if($total > $limit) { $FileCount++; $total = $total/2; print "\n$filecount - $total - $file\n\n"; } #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 $!;
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Multiple zip files from directories!
by kennethk (Abbot) on Sep 15, 2011 at 15:02 UTC | |
by Anonymous Monk on Sep 15, 2011 at 15:24 UTC | |
by Anonymous Monk on Sep 15, 2011 at 19:39 UTC | |
by kennethk (Abbot) on Sep 15, 2011 at 20:44 UTC | |
Re: Multiple zip files from directories!
by Anonymous Monk on Sep 15, 2011 at 18:54 UTC | |
by Anonymous Monk on Sep 15, 2011 at 19:23 UTC | |
by armstd (Friar) on Sep 18, 2011 at 14:32 UTC |