Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re^3: Archive::Zip - How to selectively copy files from one archive to another one?

by Mr. Muskrat (Abbot)
on Aug 12, 2012 at 21:53 UTC ( #986981=note: print w/ replies, xml ) Need Help??


in reply to Re^2: Archive::Zip - How to selectively copy files from one archive to another one?
in thread Archive::Zip - How to selectively copy files from one archive to another one?

It's all explained rather well in the docs. Archive::Zip

addFile is expecting a filename not an Archive::Zip::ZipFileMember object. Try this instead:

#!perl use strict; use warnings; use Archive::Zip qw( :ERROR_CODES :CONSTANTS ); # Include actual filenames in the next two lines my $oldfile = 'oldzip.zip'; my $newfile = 'newzip.zip'; my $oldzip = Archive::Zip->new(); $oldzip->read( $oldfile ) == AZ_OK or die 'read error'; print "$oldfile contains the following files:\n"; print " $_\n" for $oldzip->memberNames(); print "\n"; my $newzip = Archive::Zip->new(); my @wanted = $oldzip->membersMatching( '123.*\.xml' ); for my $member ( @wanted ) { print "Extracting ", $member->fileName(), " from $oldfile and addi +ng to $newfile\n"; $oldzip->extractMember( $member ); $newzip->addMember( $member ); } print "\n"; $newzip->writeToFileNamed( $newfile ) == AZ_OK or die 'error somewhere +'; print "$newfile contains the following files:\n"; print " $_\n" for $newzip->memberNames(); __END__ # Sample output oldzip.zip contains the following files: 123a.xml 123b.xml 234c.xml Extracting 123a.xml from oldzip.zip and adding to newzip.zip Extracting 123b.xml from oldzip.zip and adding to newzip.zip newzip.zip contains the following files: 123a.xml 123b.xml


Comment on Re^3: Archive::Zip - How to selectively copy files from one archive to another one?
Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://986981]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (6)
As of 2014-08-20 05:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (105 votes), past polls