I tried removing the open() and close() outside of the foreach loop, but cause of the zip gets done before the text file the log.txt file inside of the zip file is empty, any suggestions? Thanks!
#!/usr/bin/perl -w # use strict; use CGI qw(:standard); use File::Basename; use File::stat; use File::Slurp qw(read_dir); use Archive::Zip qw( :ERROR_CODES :CONSTANTS ); # zip stuff::: my $zip = Archive::Zip->new(); # new instance #Archive::Zip::setChunkSize( 2000 ); #my $chunkSize = Archive::Zip::chunkSize(); my ($file_path, $file_name, $zipped, $flag,$k_size); $flag = ''; # vars my @files; # get the files from here::: my @directories = qw( /var/www/test_1 /var/www/test_2); # set sizes::: my $min_size = 1024; # bytes => 1K my $max_size = 10485760; # bytes =>10MB # go in the directories::: my $c; for my $d (@directories) { $c++; push @files, grep { -f && -s _ >= $min_size && -s _ <= $max_size } + read_dir( $d, prefix => 1 ); } #get file sizes just in case::: open (INDEXFILE, '>>log.txt'); foreach my $files(@files) { my $size = stat($files)->size / 1024; # size in kilobytes $k_size = sprintf ("%03d", $size); # do some clean up::: $files=~s/[\r\n]+//; if($files =~/(.*?)\/([^\/]+)$/) { $file_path=$1; $file_name=$2; } # creating log file::: print INDEXFILE "$file_name - $k_size Kb\n"; $zipped = $zip->addFile('log.txt') unless $zip->memberNamed('log.txt +'); $zipped = $zip->addFile($files,$file_name); } die $flag="Failed" unless $zip->writeToFileNamed( 'test.zip' ) == AZ_ +OK; close (INDEXFILE); # show status::: if($flag eq "Failed") { print "\n\nError in archive creation!\n\n"; } else { print "\n\nArchive created successfully!\n\n"; }

In reply to Re^2: Zipping Files Help! by Anonymous Monk
in thread Zipping Files Help! by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.