Solved

zip from perl script

Posted on 2000-05-08
5
484 Views
Last Modified: 2008-02-01
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
Comment
Question by:mfuerlinger
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 84

Expert Comment

by:ozo
ID: 2787620
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
 
LVL 16

Expert Comment

by:maneshr
ID: 2788551
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
 
LVL 1

Author Comment

by:mfuerlinger
ID: 2797913
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
 
LVL 16

Accepted Solution

by:
maneshr earned 100 total points
ID: 2797964
glad to know that you were able to find a working solution!!

0
 
LVL 1

Author Comment

by:mfuerlinger
ID: 2798002
Thanks for your time :)
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

On Microsoft Windows, if  when you click or type the name of a .pl file, you get an error "is not recognized as an internal or external command, operable program or batch file", then this means you do not have the .pl file extension associated with …
A year or so back I was asked to have a play with MongoDB; within half an hour I had downloaded (http://www.mongodb.org/downloads),  installed and started the daemon, and had a console window open. After an hour or two of playing at the command …
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Six Sigma Control Plans

626 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question