Hi all,
I am very new for Perl, I tried to zip the file using the following script
#!perl -w
use strict;
use File::Find;
use Archive::Zip qw( :ERROR_CODES :CONSTANTS );
my $dir = ‘c:/siva’;
my $zip = Archive::Zip->new();
my $zipped;
$zipped = $zip->addDirectory( $dir );
$zipped->desiredCompressionMethod( COMPRESSION_DEFLATED );
find(&zip_file, $dir);
die ‘write error’ unless $zip->writeToFileNamed( ‘logs.zip’ ) == AZ_OK;
sub zip_file {
$zipped = $zip->addFile( $File::Find::name );
}
But i got the following errors. Could you please help me for solve this problem.
cannot call method “desiredCompressionMethod( COMPRESSION_DEFLATED )” on the undefined value at c:perlsitelibArchiveZipArchive.pm line 249
You have 2 problems.
1) your ‘c:/siva’ dir appears to have sub dirs which will cause a problem when you attempt to $zip->addFile( $File::Find::name )
2) when saving the file, you should supply the full path, otherwise you’ll probably end up getting this error:
Try this version.
You have 2 problems.
1) your ‘c:/siva’ dir appears to have sub dirs which will cause a problem when you attempt to $zip->addFile( $File::Find::name )
2) when saving the file, you should supply the full path, otherwise you’ll probably end up getting this error:
Try this version.