CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
Search Posts SEARCH
Who's Online WHO'S
Log in LOG

Home: Perl Programming Help: Intermediate:
zipping problems



Feb 10, 2009, 10:14 AM

Post #1 of 2 (1506 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

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_$") == AZ_OK ) {
die 'write error';

Veteran / Moderator

Feb 10, 2009, 10:56 AM

Post #2 of 2 (1504 views)
Re: [frist44] zipping problems [In reply to] Can't Post

If the files are not in the same directory as the perl script, then you'll need to include the path when adding to the archive.

(This post was edited by FishMonger on Feb 10, 2009, 10:56 AM)


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives