Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
Thanks for the Help!!!... use strict; use Archive::Zip qw( :ERROR_CODES :CONSTANTS ); ... # create zip files my $limit = 100*MB; my $zip_file = "zipfile.zip"; my $file_name = "file_file"; my $f_count = 1; $f_count = sprintf("%02d", $f_count); my $count_files; my $count_zip=0; # all the files will be in this @files (lets say all files in @files a +dd up to 500MB) array after reading from a directory foreach my $files (@files) { chomp($files); $count_zip++; $count_zip = sprintf("%02d", $count_zip); my $fsize = -s $files; #add some logic for multiple zip files::: my $temp = Archive::Zip->new; my $member = $temp->addFile($files); next unless $member->compressedSize; my $fh = tempfile(); $temp->writeToFileHandle($fh) == AZ_OK or die $!; if ($total + $member->compressedSize > $limit) { if($total > 0){ $zip_file =~ s/\.[^.]+$//; $zip_file .= "_$f_count.zip"; $zip->writeToFileNamed("temp/".$zip_file) == AZ_OK or die $!; $f_count++; $count_zip--; $total = 0; $zip = Archive::Zip->new; } } $total += $member->compressedSize; #add files to the zip files $zip->addFile($files,$file_name); # now lists all members in the archive my @rfiles = $zip->memberNames(); my $c=0; # read all the files inside of each zip file listing their names to + crerate a report open REPL, ">report_list.txt" or die $!; foreach my $rfiles (@rfiles) { $c++; print REPL "$c - $rfiles\n"; } close (REPL); $zip->addFile('report_list.txt') unless $zip->memberNamed('report_l +ist.txt'); }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Adding files to ZIP files!
by Lotus1 (Vicar) on Jan 13, 2012 at 19:03 UTC | |
|
Re: Adding files to ZIP files!
by InfiniteSilence (Curate) on Jan 13, 2012 at 19:07 UTC | |
by Anonymous Monk on Jan 13, 2012 at 19:20 UTC | |
by InfiniteSilence (Curate) on Jan 14, 2012 at 17:52 UTC |