• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 549
  • Last Modified:

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
0
mfuerlinger
Asked:
mfuerlinger
  • 2
  • 2
1 Solution
 
ozoCommented:
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 \
0
 
maneshrCommented:
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;


0
 
mfuerlingerAuthor Commented:
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
0
 
maneshrCommented:
glad to know that you were able to find a working solution!!

0
 
mfuerlingerAuthor Commented:
Thanks for your time :)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now