use File::Archive extracting zip's with '.' in front of name

D

david

I have a script to extract any ZIP files in the current directory. The
problem is when they are extracted, the program puts a . in front of
the file names.

#!/usr/bin/perl -w

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

opendir(DIR, ".") || die "Can't open local directory : $!";
my @zips = grep { -f "./$_" } readdir (DIR);
close(DIR);
foreach my $zipfiles (@zips) {
if ($zipfiles =~ /\w+\.zip$/) {
my $zip = Archive::Zip->new();
my $zipName = "$zipfiles";
my $status = $zip->read( $zipName);
die "Read of $zipName failed\n" if $status != AZ_OK;
print "$zipfiles\n";
$zip->extractTree();
#unlink($zipfiles);
}

}

If I have a file called a.zip with a file in it called 'a', the script
will extract it as '.a'

How can I get around this?

Thanks,
 
S

Sisyphus

david said:
I have a script to extract any ZIP files in the current directory. The
problem is when they are extracted, the program puts a . in front of
the file names.

#!/usr/bin/perl -w

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

opendir(DIR, ".") || die "Can't open local directory : $!";
my @zips = grep { -f "./$_" } readdir (DIR);
close(DIR);
foreach my $zipfiles (@zips) {
if ($zipfiles =~ /\w+\.zip$/) {
my $zip = Archive::Zip->new();
my $zipName = "$zipfiles";
my $status = $zip->read( $zipName);
die "Read of $zipName failed\n" if $status != AZ_OK;
print "$zipfiles\n";
$zip->extractTree();
#unlink($zipfiles);
}

}

If I have a file called a.zip with a file in it called 'a', the script
will extract it as '.a'

I don't think Archive::Zip is supposed to do this - but it does (for me on
Win2k, perl 5.6.1).
How can I get around this?

I think you'll get around it with :
$zip->extractMember($member_name);

See Archive::Zip docs.

Hth,

Cheers,
Rob
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,236
Members
46,822
Latest member
israfaceZa

Latest Threads

Top