Maybe you can help us improve the documentation and propose a change that would make it clearer how the ->extractMember method accepts an optional second parameter which is the name under which the extracted file is saved.
| [reply] [d/l] |
Hold the sarcasm, I think he's actually asking how to extract a file to a specific directory, and not just with a different name. So the solution is not that trivial.
I think indeed either extractMember or extractMemberWithoutPaths, where you first construct the full path for the new file, from the old member name.
Actually, I think Archive::Zip could use an edit, where you could pass a path to a directory (either an existing directory or a path that ends in a slash/backslash/other directory separator), which would then serve as a root dir for the extraction. It currently doesn't do that, the optional path must include the file name.
So, the OP needs to add some code constructing the new path name out of the member name, and use that as a second parameter to extractMember.
You can retrieve the internal path for a member by using the snippet
$name = $member->fileName();
Do ZIP archives use absolute or relative paths? If it's relative path, it'll use the current directory as the root dir. In that case it's easy: just chdir to the directory that you want to use as the root for the decompressed archive.
| [reply] [d/l] [select] |
use strict;
use Archive::Zip;
my $destinationDirectory = 'C:\test'; #####Specify your destination di
+rectry to unzip the file
my $zip = Archive::Zip->new('C:\00000007.zip'); #####This is the sourc
+e zip file path
foreach my $member ($zip-> members){
my $extractName = $member->fileName;
$member->extractToFileNamed("$destinationDirectory\\$extractName")
+;
}
Punitha | [reply] [d/l] |
| [reply] [d/l] [select] |
If your task is concerned only with extracting content from zip files (as opposed to creating them), you should look at Archive::Extract (as suggested in the Archive::Zip manual). The "extract" method of that other module accepts a "to => $target_path" parameter to control where the extracted data is stored.
| [reply] |
my $endpath = 'C:\blah\blah\;
foreach (@members){
$zip->extractMember( $_, "$endpath\\$_");
}
| [reply] [d/l] |
| [reply] |