Click here to get back home

Using Archive::Zip extractTree();

 HomeNewsGroups | Search | About
 comp.lang.perl.modules    Post an article   get this group's latest topics as an RSS feed add this group's latest topics to your My MSN content add this group's latest topics to your My Yahoo content
Subject Author Date
Using Archive::Zip extractTree(); eldwin 01-02-2007
Posted by eldwin on January 2, 2007, 4:33 pm
Please log in for more thread options


Hello All,

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

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
directory.

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";

opendir(DIR,".");

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);
        }

}

closedir(DIR);
print "\n";
exit;

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

--Eldwin


Posted by Jim Gibson on January 2, 2007, 5:40 pm
Please log in for more thread options



> Hello All,
>
> I'm new to perl and I'm attempting to write a script that does the
> following:
>
> 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
> directory.
>
> 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";
>
> opendir(DIR,".");
>
> 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);

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.

> }
>
> }
>
> closedir(DIR);
> print "\n";
> exit;
>
> The directories are created, but the .zip1 files are not unzipped to
> the created directories ($tempdir).
> Any advice will be appreciated. Thanks.

Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------
http://www.usenet.com

Posted by edSanDiego on January 2, 2007, 6:30 pm
Please log in for more thread options



> 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.
>

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,

--Eldwin


Similar ThreadsPosted
Archive::Tar August 14, 2004, 9:41 am
[ANN] Archive::Zip 1.12 released July 12, 2004, 8:21 pm
Archive::Tar on win32 September 16, 2004, 8:40 am
[ANN] Archive::Zip 1.14 released October 22, 2004, 4:04 pm
[ANN] Archive::Zip 1.14 released October 22, 2004, 11:03 pm
Archive::Zip problem July 3, 2006, 5:25 am
Archive::Tar fails tests on AIX August 17, 2004, 6:30 pm
ANNOUNCE: Archive::Zip 1.13 released August 23, 2004, 4:49 pm
Archive::Zip missing pod2man? September 12, 2004, 7:33 pm
Archive::Tar and how to handle *.bz2 archives? September 13, 2005, 3:18 pm

Our other projects:

Art Dolls, Fairies and Mermaids - Sunnyfaces.net

Roy's Linux, Programming and Search Engines messages

1-Script XML SitemapXML Sitemap