Zitoune has asked for the wisdom of the Perl Monks concerning the following question:

I'm using the Archive::Zip module. When extracting files from my ZIP, i would like to give a path for where to extract it.
This is the code i'm using :
$zipfile="$Inbox"."\\"."$x"; $zip=Archive::Zip->new($zipfile) or die "Unable to Open the Fi +le : $zipfile\n"; for $x ( $zip->members() ) { $zip->extractMemberWithoutPaths($x); }

I'm sure someone would know how do to this.
Thanks
Oliver

Replies are listed 'Best First'.
Re: Path Of an extracted Files
by chip (Curate) on Mar 11, 2004 at 17:58 UTC
    Use the extractMember() function and provide a second argument, which will be used as the output name.

    PS: RTFM!

        -- Chip Salzenberg, Free-Floating Agent of Chaos

      I know that. But you can't give a specific path when doing this.
      I tried it and it was giving me thsi error :
      mkdir AFCUArchive::Zip::.: Invalid argument at C:/Perl/site/lib/Archive/Zip.pm line 1760
        You can give a specific path, that's what the FM says, which you should R. Maybe you're giving an invalid path, which would explain why the mkdir() is failing.

            -- Chip Salzenberg, Free-Floating Agent of Chaos

Re: Path Of an extracted Files
by Zitoune (Beadle) on Mar 11, 2004 at 18:11 UTC
    This is how i'm doing it :
    print "Y:\\autoupload\\Site_Dict\\Inbox\\$y\n"; $zip->extractMemberWithoutPaths($y,"Y:\\autoupload\\Site_D +ict\\Inbox\\"."$y");
    Oliver
      To summarize the problem (which I gather you haven't figured out yet)... Here's your code that causes the error:
      $zip->extractMemberWithoutPaths($y,"Y:\\autoupload\\Site_Dict\\Inbox\\ +"."$y");
      And here's the error report that you say it generates:
      mkdir AFCUArchive::Zip::.: Invalid argument [somewhere in Archive::Zip +]
      (which frankly doesn't look like what I would expect, but I suppose it's plausible enough). And here's the relevant part of the Archive::Zip man page (you did read this part, didn't you?):
      extractMemberWithoutPaths( $memberOrName [, $extractedName ] ) Extract the given member, or match its name and extract it. Does not use path information (extracts into the current directory). Returns undef if member doesn't exist in this Zip. If optional second arg is given, use it as the name of the extracted member (its paths will be deleted too)...
      From reading the man page, I would conclude that you are not supposed to try to specify a path for output as (part of) an arg being passed to this method. Instead, you would want to do something like this:
      # read the zip file into $zip, then chdir $path_where_data_should_go or die "Can't get to $path_where_data_should_go: $!"; for my $mbr ( $zip->members ) { $zip->extractMemberWithoutPaths( $mbr ); }