
frist44
User
Feb 10, 2009, 10:14 AM
Post #1 of 2
(680 views)
|
|
zipping problems
|
Can't Post
|
|
I'm writing a script that will take the path of a directory as an argument. So if I run it with the Desktop directory (where there are 2 log files), it zips both logs and properly and creates the .zip file. If i run it with a directory other than my desktop (that has several log files), it creates the zip file, outputs the names of the log files, so it's definitely getting that part, but doesn't actually add them to the zip file. Any idea?
use Time::localtime; use Net::SMTP; use Archive::Zip qw( :ERROR_CODES :CONSTANTS ); use Date::Simple (':all'); use strict; # Get path of log files my $log_path = $ARGV[0]; #Run the main subroutine main(); sub main { zip( $log_path ); } # This subroutine zips the contents of the specified directory sub zip { # Bring in the passed parameters my ($s_dir) = @_; # Get current date my $today = today(); # Create a Zip file my $zip = Archive::Zip->new(); # Assign the names of the .log files in the directory to an array opendir DIR, $s_dir or die "cannot open dir $s_dir: $!"; my @file= grep (/\.log/,readdir (DIR)); closedir DIR; # For each file in the directory, add to zip foreach (@file) { $zip->addFile( $_ ); print $_; } # Save the Zip file unless ( $zip->writeToFileNamed("IIS_logs_$today.zip") == AZ_OK ) { die 'write error'; } }
|