Professional Web Applications Themes

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

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

  1. #1

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

    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 Guest

  2. #2

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


    "david" <dwlepage> wrote in message
    news:b09a22ae.0307261357.1812f9dposting.google.co m...
    > 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 Guest

Similar Threads

  1. Extracting Image from PDF file
    By Venkatesh_Rajasekaran@adobeforums.com in forum Adobe Acrobat SDK
    Replies: 2
    Last Post: September 5th, 06:12 PM
  2. Extracting an img file
    By Warren in forum FreeBSD
    Replies: 1
    Last Post: February 26th, 09:04 AM
  3. Extracting the info from a file
    By Jewb2 in forum Coldfusion - Advanced Techniques
    Replies: 0
    Last Post: February 20th, 07:35 PM
  4. Replies: 0
    Last Post: June 30th, 12:58 AM
  5. Help with extracting text file
    By Zary Necheva in forum PERL Beginners
    Replies: 4
    Last Post: November 26th, 12:58 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139