Perl Module Archive::Zip - 我如何知道成员是否是文件目录?
关于 Archive::Zip
的一个简单问题。我如何知道成员是目录还是文件?我需要将特定 Zip 中的所有 Ear 文件移动到另一个目录。但是,某些目录也有 .ear
后缀,我不想要这些。
我正在做:
my @jarMembers = $zip->membersMatching('^.*\.jar');
foreach my $member (@jarMembers) {
my $fileName = basename($member->FileName());
$zip->ExtractMember($member, "$zipRootDir/$fileName";
}
我想验证我不会获取目录 foo.ear 。
我怀疑目录名称应该以斜杠结尾,但文档中没有明确说明这一点。我还注意到特殊的 Archive::Zip::FileMember 方法,但访问它们的文档方式并不多。难道只是这么简单的事吗?
if ($member->externalFileName()) {
print "Member is a file\n";
} else {
print "Member is a directory\n";
}
这会告诉我成员是文件还是目录,或者我的第一个代码片段是否足够?
A quick question with Archive::Zip
. How do I know whether a member is a directory or file? I need to move all Ear files in a particular Zip to another directory. However, some directories also have the .ear
suffix, and I don't want those.
I'm doing:
my @jarMembers = $zip->membersMatching('^.*\.jar');
foreach my $member (@jarMembers) {
my $fileName = basename($member->FileName());
$zip->ExtractMember($member, "$zipRootDir/$fileName";
}
And I want to verify I won't be getting the directory foo.ear
.
I suspect that directory names are suppose to end in a slash, but there's nothing in the documentation that explicitly states that. I also notice special Archive::Zip::FileMember methods, but not much in the way of documentation in accessing them. Is it simply something like this?
if ($member->externalFileName()) {
print "Member is a file\n";
} else {
print "Member is a directory\n";
}
Will that tell me whether or not a member is a file or a directory, or is my first code snippet sufficient?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我的 Perl 版本(Mac OS X 10.6.5 上的 5.10.0)在
Archive::Zip::Member
中有这个方法:My version of Perl (5.10.0 on Mac OS X 10.6.5) has this method in
Archive::Zip::Member
: