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

Discussion in 'Perl Misc' started by david, Jul 26, 2003.

  1. david

    david Guest

    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,
    david, Jul 26, 2003
    #1
    1. Advertising

  2. david

    Sisyphus Guest

    "david" <> wrote in message
    news:...
    > 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
    Sisyphus, Jul 27, 2003
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Brandon Taylor
    Replies:
    8
    Views:
    2,648
    Brandon Taylor
    Feb 5, 2009
  2. Twig
    Replies:
    1
    Views:
    120
    A. Sinan Unur
    Jan 27, 2006
  3. Replies:
    2
    Views:
    152
  4. MoshiachNow

    Archive::Zip - zip file has "invalid" format

    MoshiachNow, Oct 5, 2006, in forum: Perl Misc
    Replies:
    1
    Views:
    151
  5. Bo Yang
    Replies:
    9
    Views:
    288
    -berlin.de
    Nov 20, 2006
Loading...

Share This Page