Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
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 having an uproarious good time at the Monastery: (8)
As of 2015-07-07 00:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (85 votes), past polls