in reply to Checking if a file is present in a ZIP archive

Archive::Zip#ERROR_CODES (couldn't get the link to ERROR_CODES to work).

use Archive::Zip qw(:ERROR_CODES :CONSTANTS); my $zip2_path = 'c:/usr/test/file.zip'; my $zip2 = Archive::Zip->new(); unless ( $zip2->read( $zip2_path ) == AZ_OK ) { die "$zip2_path read error"; }

It does return an error if you call it this way. It says in the module docs at cpan you can put the file name in the constructor but you don't get the error code. If you read it with an object method like this you do. Also, did you check for .zip ending? That doesn't guarantee anything but could weed out files that shouldn't be attempted to open.

Replies are listed 'Best First'.
Re^2: Checking if a file is present in a ZIP archive
by bontchev (Sexton) on Mar 25, 2011 at 20:41 UTC
    This is almost exactly how I tried it initially - except that I don't die with an error message; I just skip the file. It is how common sense suggests that the package should behave. But it DOES NOT! Try passing it a text file instead of a ZIP archive and you'll see. It will spew half a screen of error messages (basically complaining about the lack of signature and going downhill from there), instead of keeping silent and simply returning some error code that is not AZ_OK.