Solved

zip from perl script

Posted on 2000-05-08
5
477 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
  • 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Perl script to parse log and delete the file 17 177
Perl 101 11 81
Get a Perl script to return content from a module 7 82
Perl script to process a .csv file 18 44
I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
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…

839 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