sub ZipFiles { use Archive::Zip qw(:ERROR_CODES :CONSTANTS); my $ret = 0; my @msg = (); if ( @_ > 1 ) { my $fileName = shift; my @fileNames = @_; $fileName =~ s/\.zip//; my $zip = Archive::Zip->new(); foreach my $memberName (@fileNames) { if (-d $memberName ) { push(@msg, "Error: Could not add directory $memberName to zip file.") if $zip->addTree( $memberName, $memberName ) != AZ_OK; } else { $zip->addFile( $memberName ) or push(@msg, "Error adding file $memberName\n"); } } if ($zip->writeToFileNamed( "$fileName.zip" ) != AZ_OK ) { $ret = 1; push (@msg, "Error: Zip file could not be created. A write error has occured. Verify that specified directory is correct."); } } else { $ret = 1; push(@msg, "Error: Number of arguments does not match specified amount."); } if ( $ret == 0 ) { @msg = (); push(@msg, "Files have been zipped successfully."); } return wantarray ? ($ret, @msg) : $ret; }