Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Archive::Zip - is a member directory ?

Status
Not open for further replies.

MoshiachNow

IS-IT--Management
Feb 6, 2002
1,851
IL
Hi,

Unzipping from a zip file,I need to establish if the member is a directory or a file.
The following code does not seem to do it it for me,the result is always ZERO (a file..).
Appreciate any advise:

$zip = Archive::Zip->new();
die if $zip->read( $filename1 ) != AZ_OK;
if (Archive::Zip::Member->isDirectory($NAME)) {
do something ...

I have also tried:
if ($zip->isDirectory($NAME)) {
$NAME passed can be directory or a file,and I expect "1" if it's a directory.
The exit code from the above is always Zero ...Why ?
Surely something is wrong with my syntax.
Thanks

Long live king Moshiach !
 
I don't know, looks like it should work....

- Kevin, perl coder unexceptional!
 
Thanks,

but it does not,and I need a proper syntax,or another option to tell if my arcive member is a file or directory.

Thanks

Long live king Moshiach !
 
Read the documentation a little more carefully:


isDirectory() is an instance method of the Archive::Zip::Member class. In your first attempt you use it as a class method of Archive::Zip::Member, and in your second as an instance method of Archive::Zip. Also, in the documentation you will notice that it doesn't accept any parameters. This should also clue you into that you aren't using it correctly.

Here is a working version of what you were attempting:

Code:
# Read a Zip file
my $zip = Archive::Zip->new();
unless ( $zip->read( $filename1 ) == AZ_OK ) {
    die 'read error';
}

# Read a member
my $member = $somezip->memberNamed( $NAME );
if ($member->isDirectory()) {                    
  do something ...

Note: if the member does not exist, then memberNamed will return undef.

If you just want to toggle through the members use $zip->members();
 
Guys,

I think it's fair to assume that the guy with a question DID read the docs,but there is sometimes a limit to the extent he understood it.
I do not have much experience with object oriented staff,so I needed an advice.
Thanks for it.

Long live king Moshiach !
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top