perl - Use Archive::Zip to determine if a member is a text file or not -
i'm working on script grep contents of members of zip archives when member name matches pattern, using given search string.
i have following sub processes single archive (the script can take more 1 archive on command line):
sub processarchive($$$$) { ($zip, $searchstr, $match, $zipname) = @_; print "zip[$zip] searchstr[$searchstr] match[$match] zipname[$zipname]\n"; @matchinglist = $zip->membersmatching($match); $len = @matchinglist; if ($len > 0) { print $zipname . ":\n"; $member (@matchinglist) { print "member[$member]\n"; print "textfile[" . $member->istextfile() . "] contents[" . $member->contents() . "]\n"; if ($member->istextfile()) { print "is text file.\n"; } else { print "is not text file.\n"; } @matchinglines = grep /$searchstr/, $member->contents(); $len = @matchinglines; if ($len > 0) { print @matchinglines; } } } }
the logic isn't complete yet. i'm first experimenting calling "istextfile()" see does. must doing wrong, because "is not text file" @ least 1 member text file.
i note when print value of return "istextfile()", it's empty string. should expect printing "true" or "false" value, or else wrong here?
the "text file" status read flag in zip file. many archiving tools not set flag properly, used , has no impact on normal use.
if need check whether file contains text, need extract , see yourself.
Comments
Post a Comment