Steve Tempest
asked on
Unzip only files from zip file.. junk the paths
Hi,
I have some code using Archive::Zip that will extract the data from a zip file into a destination folder. I'm not able to work out how not to keep the directory structure of the zip and only extract the files.
I would like to do something simulart to
unzip -o -j /zipfile.zip
I am not able to get Archive::Zip to junk the paths in the zip file.
Thanks
Steve
I have some code using Archive::Zip that will extract the data from a zip file into a destination folder. I'm not able to work out how not to keep the directory structure of the zip and only extract the files.
I would like to do something simulart to
unzip -o -j /zipfile.zip
I am not able to get Archive::Zip to junk the paths in the zip file.
Thanks
Steve
You could use the extractMemberWithoutPaths function. What are you doing now?
ASKER
Hi,
Thanks for the replies.
Here is what I have now which works thanks suhasbharadwaj.
I would prefer not to break out to a shell to perform this operation so I'm leaving this item open for 1 more day to see if extractMemberWithoutPaths is possible.
I had a go at it and could not get it working with extractMemberWithoutPaths but if someone can provide a code snippit that would be great.
Thanks
Steve
Thanks for the replies.
Here is what I have now which works thanks suhasbharadwaj.
I would prefer not to break out to a shell to perform this operation so I'm leaving this item open for 1 more day to see if extractMemberWithoutPaths is possible.
I had a go at it and could not get it working with extractMemberWithoutPaths but if someone can provide a code snippit that would be great.
Thanks
Steve
sub unzip_this_junk_paths{
my ($zipfile, $destination, $error_path) = @_;
my $zip = Archive::Zip->new();
unless ( $zip->read( "$zipfile" ) == AZ_OK ) {
move("$zipfile", "$error_path/.") and die;
}
system("unzip \-o \-j \-qq $zipfile -d $destination");
}
use Archive::Zip;
my $zip = Archive::Zip->new( 'test1.zip' );
$zip->extractMemberWithoutPaths($_) foreach ($zip->members);
ASKER
Is it possible to pass the destination using this method?
ASKER
also will this overwrite existing files without failing which is what the -o is doing in the system call
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
you can use system("unzip \-o \-j \/zipfile\.zip");
Regards,
suhasbharadwaj