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

I am using following code to extract the files and directories from a zip file.

$filename = "somefile.zip"; $dest_dir = "c:/somedir"; my $zip = Archive::Zip->new(); local $Archive::Zip::UNICODE = 1; unless ( $zip->read($filename) == AZ_OK ) { die "Error Reading Zip File !"; } my @members = $zip->members(); foreach (@members){ $zip->extractMemberWithoutPaths( $_, "$dest_dir\\$_"); }

The problem i am facing is that it is unable to extract the zero size file(if any) which exists in at any directory level. Can somebody please share some references here? I am using "Straberry perl" on Windows 2012.

Replies are listed 'Best First'.
Re: Problem extracting zero size files from zip.
by RichardK (Parson) on Jul 21, 2015 at 12:51 UTC

      Thanks a lot for sharing this information. I was using version 1.38 and it has been fixed in version 1.41. Upgraded the package and it is working fine now. Thanks

Re: Problem extracting zero size files from zip.
by vinoth.ree (Monsignor) on Jul 21, 2015 at 13:00 UTC
    #!/usr/bin/perl use strict; use warnings; use Archive::Zip qw(:ERROR_CODES :CONSTANTS); my $filename = "XXXXXXXXXXXx.zip"; my $zip = Archive::Zip->new(); unless ($zip->read($filename) == AZ_OK) { die "Read error\n"; } my @members = $zip->members(); foreach (@members) { #Try to use any of the following function #unless ($_->compressedSize()) (OR) #unless($_->uncompressedSize()) }

    Loop through the members, use compressedSize() or uncompressedSize() function to find the file size is zero and do what you want in if condition.

    Not Tested, Just an Idea.

    All is well. I learn by answering your questions...