Using Archive::Zip extractTree();

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View

Hello All,

I'm new to perl and I'm attempting to write a script that does the

1) Open the directory and copy the .zip1 file name to a variable
2) create a new directory (using the .zip1 file name as the name of the
new directory.)
3) Unzip the .zip1 file to it's newly created directory.
4) Edit the files that were unzipped to the directory.
5) Zip the edited files to a new .zip1 file and put them in a FINISHED

Here's what I have so far.

#!/usr/bin/perl -w

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

my $zip = Archive::Zip->new();
my $workdir; #Working directory where zip1 are unpackaged
my $tempdir;
my $status;

print "\n\nScanning directory for .zip1 files...\n\n";


while ($workdir=readdir(DIR))
    if($workdir =~ /zip1/)
        mkdir $workdir."_UNPACKED";
        $tempdir = $workdir."_UNPACKED";
        print "Creating Working Directory: $tempdir\n";
        $status = $zip->read($workdir);
        die "Read of $workdir failed\n" if $status != AZ_OK;
        $zip->extractTree($workdir, $tempdir);


   print "\n";

The directories are created, but the .zip1 files are not unzipped to
the created directories ($tempdir).
Any advice will be appreciated. Thanks.


Re: Using Archive::Zip extractTree();

Quoted text here. Click to load it

Read the documentation for extractTree. The first argument is not the
name of the zip file, it is the root name of all of the files in the
zip file to be extracted. If none of the files stored in the zip file
have the same root name as the name of the zip file itself (a likely
occurrence), no files will be extracted. Try cd'ing to the destination
directory and using extractTree with no arguments. Try using '' as the
first argument. If those don't work, try accessing the names of the
zipped files (with members() perhaps) and extracting them individually.
I have not used Archive::Zip and am just suggesting possibilities from
the documentation.

Quoted text here. Click to load it

 Posted Via Premium Usenet Newsgroup Services

Re: Using Archive::Zip extractTree();

Quoted text here. Click to load it

Thanks for the reply. I totally misunderstood the documentation. I've
fixed the script and it now unzips to the proper directories.

This is the change I made:

    $zip->extractTree(' ' , ' ', $tempdir);

Thanks again,


Site Timeline