For Programmers: Free Programming Magazines  


Home > Archive > PERL Beginners > May 2004 > Move file from one zip to another using Archive::Zip









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Move file from one zip to another using Archive::Zip
carl@dc.rr.com

2004-05-19, 2:30 pm

Hola,

How do I remove a file from a zip file and add it to a different existing archive? From the Archive_Zip documentation I understand that I'm clobbering the existing archives when i use the code below. How do I not clobber them?

thank you.


use Archive::Zip qw( :ERROR_CODES :CONSTANTS );

my $from_zip = Archive::Zip->new();
my $to_zip = Archive::Zip->new();
my $member = $from_zip->removeMember( '000002031_02498_02498_policy_o1_2775057
.pdf' );
$to_zip->addMember( $member );

die 'write error' unless $from_zip->writeToFileNamed( 'INITIAL_2498_20040514_1.zip' ) == AZ_OK;
die 'write error' unless $to_zip->writeToFileNamed( 'INITIAL_2498_20040514_2.zip' ) == AZ_OK;

exit;



Wiggins D Anconia

2004-05-19, 4:30 pm

> Hola,
>
> How do I remove a file from a zip file and add it to a different

existing archive? From the Archive_Zip documentation I understand that
I'm clobbering the existing archives when i use the code below. How do
I not clobber them?
>
> thank you.
>
>
> use Archive::Zip qw( :ERROR_CODES :CONSTANTS );
>
> my $from_zip = Archive::Zip->new();
> my $to_zip = Archive::Zip->new();


You don't confirm that new was actually successful. I couldn't see how
it indicates errors. You also haven't added anything to the Archive::Zip
objects above, like a file, are you sure the object has members to begin
with?

> my $member = $from_zip->removeMember(

'000002031_02498_02498_policy_o1_2775057
.pdf' );
> $to_zip->addMember( $member );
>


This looks right, but again you aren't doing any error checking to see
if something has gone wrong, it might indicate what your problem is.

> die 'write error' unless $from_zip->writeToFileNamed(

'INITIAL_2498_20040514_1.zip' ) == AZ_OK;
> die 'write error' unless $to_zip->writeToFileNamed(

'INITIAL_2498_20040514_2.zip' ) == AZ_OK;
>


Is this real code? If not, show us, that we might be able to provide
more help. If this is real code you are going to need to read the zip
file into the 'from' object...

http://danconia.org

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com