Link to home
Start Free TrialLog in
Avatar of mfuerlinger
mfuerlinger

asked on

zip from perl script

Newbie has the following question:

I'm using the zip -command with the 'system' directive in a perl script.
(e.g. system (zip /home/test/test.zip /home/data/source1.txt /home/data/source2.txt);)

The script is run by the webserver (User:wwwrun(nogroup))


The source files come from a script generated filelist-Variable.
Wildcards are useless for my needs.

I've got more than 100 source files, all resident in the same directory.

1. Is there a way to use the same path for all source files
instead of using the whole path for every source-file entry ?

2. How many source files (how many lines of source files) does the zip-routine accept
for input ?

zip offers the possibilty to specify the file list with "-@"
I tried to make an include.list and an exclude.list
Nothing worked ? Any hints, help ?

Thanks in advance

Mfuerlinger
Avatar of ozo
ozo
Flag of United States of America image

1. how about doing a chdir to the directory
2. may be limited by your command shell (you might try using a multi-argument system call to bypass the command shell)
in quotes, qq"-@" may need \
Avatar of maneshr
maneshr

if you dont mind use a PERL module for zip'ing the files, you can use the Archive::Zip module.


The Archive::Zip module  allows a Perl program to create, manipulate,
read, and write Zip archive files.

Zip archives can be created, or you can read from existing zip files.
Once created, they can be written to files, streams, or strings.

Members can be added, removed, extracted, replaced, rearranged, and
enumerated.  They can also be renamed or have their dates, comments, or
other attributes queried or modified.  Their data can be compressed or
uncompressed as needed.  Members can be created from members in existing
Zip files, or from existing directories, files, or strings.

This module uses the Compress::Zlib library to read and write the
compressed streams inside the files.

Here is a small example.

#!/bin/perl -w
# Creates a zip file, adding the given directories and files.
# Usage:
#      perl zip.pl zipfile.zip file [...]

use strict;
use Archive::Zip qw(:ERROR_CODES :CONSTANTS);

die "usage: $0 zipfile.zip\n"
      if (scalar(@ARGV) < 2);

my $zipName = shift(@ARGV);
my $zip = Archive::Zip->new();

foreach my $memberName (@ARGV)
{
      my $member = -d $memberName
            ? $zip->addDirectory( $memberName )
            : $zip->addFile( $memberName );
      warn "Can't make member $memberName\n" if ! $member;
}

my $status = $zip->writeToFileNamed($zipName);
exit $status;


Avatar of mfuerlinger

ASKER

I tried both of your suggestions ... and found another solution which fits my needs:

for (@filelist)     {
     $zipfile = "$path/$_\n";
     $zipcmd = "zip -j -D -X /home/test/ $zipfile\n";
system($zipcmd);
                         }

To finish this question I gonna give the points to the one who replies FIRST to my comment.

ENJOY

Mathias
ASKER CERTIFIED SOLUTION
Avatar of maneshr
maneshr

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks for your time :)